Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts

Wednesday, June 30, 2010

Role Based Access Control

RBAC(Role Based Access Control) is something that is very common in the day-to-day world.
So what is this all about.It is just about a authorization check on whether you have the access to a particular resource or not.
When faced with scenarios like this when developing applications, where you have to implement Role based access for the different users that are to use the system you might be confused on how to implement this.
Say you have a WCF service exposing a set of services.You have a WPF thick client consuming this service.Say for example you are exposing a service to Add/Delete/View Employees.Based on the various roles you need to allow/disallow the access to the functionality.The easiest way would be enable/disable the controls that would be used invoke the corresponding functionality,based on the user role.
So am I done?
What if tomorrow you are exposing this service to some other client of yours,who is to develop his on User Interface(UI) for the service.
Do I have a problem here?
Yes of course!!!
What if he does not make the same check on the UI to enable/disable the controls that would act as his inputs.So here exactly is where you have a access break.Any user will be able to perform all functions irrespective of the access specified for him.
So how do I go about?
Make this check at the service level itself.Check for access and throw a NoAccess exception if not authorized.What exactly happens when you try to enter a no-access area in your office :)
UI synchronization is an added level to this,so that you can stop unnecessary service calls.

Will soon post a implementation sample :)

Friday, September 11, 2009

Deleting Multiple Selected Items in WPF

Hi,
Many a times while using listbox,listview etc there might be a need to delete the multiple selected items.
This can be easily achieved by the following piece of code

While ControlName.SelectedItems.Count > 0
ControlName.Items.Remove(ControlName.SelectedItem)
End While

Happy Coding :)

Tuesday, August 25, 2009

WPF Certification !!!!!

After a long time after my first microsoft certification,70-536,.NET Framework - Application Development Foundation today i have taken the certification for WPF, Microsoft .NET Framework 3.5, Windows Presentation Foundation Application Development,70-502.
This one is easy for anyone who has some hands on experience in WPF.One has to be familiar with the different panels and layout,Binding,Styles and Templates.Other than that some knowledge on click once deployment would also be of help.
The best way to prepare for this,would be to have a visual studio up and running and try out different things on WPF.
I would suggest the books Sams WPF Unleashed and Pro WPF to start with.Both are really helpful.Apart from that check out the various blogs and forums out there.Just google and you would find a hell lot of those,just like you found this one:)
Just gonna relax the day ahead after the hard earned certification :):)

Thursday, August 20, 2009

SolidColorBrush List from Brushes

Hi,
Everybody will be using Brushes,which implements a set of predefined SolidColrBrush objects,to choose various colors.
Sometimes you may want to get a list of all these brushes up in your application,so that the user can select the color of his/her choice.
To get the list of colors from Brushes you can use the following piece of code


Dim dictBrushes As New Dictionary(Of String, SolidColorBrush)
For Each objPropertyInfo As PropertyInfo In GetType(Brushes).GetProperties
If (objPropertyInfo.PropertyType Is GetType(SolidColorBrush)) Then
dictBrushes.Add(objPropertyInfo.Name,objPropertyInfo.GetValue(Nothing, Nothing))
End If
Next


Here dictBrushes will give what you want.
You can use this in your view,bind to a combobox if you want and show the possible selections of color

Hope it helps :)

Thursday, August 6, 2009

Scrolling a Disabled Listbox in WPF

Recently I had a requirement when developing an application,where i needed a listbox which was to be disabled but yet can be scrolled,so that all the contents in it was visible.Applying the property,IsEnabled=False makes the whole listbox disabled even disabling the scroll.
I just found out a way around this.I created a custom listbox(MyScrollableListbox) with a property IsItemsEnabled.Setting this property to true,gives the normal listbox behaviour.When set to false only the ItemsPresenter of the listbox is disabled,so that scrolling is possible

The Custom Listbox looks like this(just one property added for now)


Public Class MyScrollableListbox
Inherits ListBox

Public Property IsItemsEnabled() As Boolean
Get
Return GetValue(IsItemsEnabledProperty)
End Get

Set(ByVal value As Boolean)
SetValue(IsItemsEnabledProperty, value)
End Set
End Property

Public Shared ReadOnly IsItemsEnabledProperty As DependencyProperty = _
DependencyProperty.Register("IsItemsEnabled", _
GetType(Boolean), GetType(MyScrollableListbox), _
New FrameworkPropertyMetadata(Nothing))

End Class


In the xaml(or if you are going to make it a custom control then you can give it in your Generic.xaml)


 <Grid>
        <local:MyScrollableListbox x:Name="ListBox1"   Margin="41,35,0,0" Height="83" HorizontalAlignment="Left" VerticalAlignment="Top" Width="69">
            <local:MyScrollableListbox.Style>
                <Style TargetType="{x:Type local:MyScrollableListbox}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Border>
                                    <ScrollViewer>
                                        <ItemsPresenter IsEnabled="{Binding Path=IsItemsEnabled, RelativeSource={RelativeSource TemplatedParent}}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
                                    </ScrollViewer>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </local:MyScrollableListbox.Style>
        </local:MyScrollableListbox>
    </Grid>


Now if you set the property IsItemsEnabled to false the listbox will be disabled,but allowing you to scroll.


edit: Added in CodeProject

Hope it helps :)