Friday, October 2, 2009

Do Stars Count????

Quite a few of you might be thinking on what this "Stars" are :).It's nothing other than the " little medals under ones Display Name ".Think I have put you again in thought.Not for too long but,it is the MSDN forum rating that I am talking about.
I started answering posts as a pastime.Soon I noticed this little stars ,varying in count, under different display names.A little bit of exploration gave me this piece of information.
The 'Pastime' turned an 'Addiction'.

"Do they pay you??"
"Are you rewarded??"
"They might give you something!!""

The common statements that I heard, whenever people see me browse the forum.
None of these were the reason for my addiction though.It was just the personal satisfaction I get from answering the questions, a new learning and a different perspective for some of the problems I had already faced.

"It's not money that always counts.....
.....Stars too count"

Monday, September 14, 2009

Ebook Or Hard Copy

Hi,
Of late I have developed the habit of reading books,most of them technical and few others which i feel interesting or of controversial topics.Now in the era of computers you get all the books of choice available right at the click of a button.But I prefer the Hard copies rather than the soft one.
Usually I go through the e-version of the book to get a feel about it,before buying.
Whether to read the ebook or the hard copy is purely of personal interest.I prefer the latter just coz of the feeling of having a book in hand and reading is great rather than sitting in front of a monitor/pda.Moreover I spent a lot of time in front of the monitor,coz my work demands it ,so i just don't want to add a reason to spend more.

The question is not "which is better",it's just about getting into the habit of reading :)

Happy Reading :)

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 :)

Wednesday, June 10, 2009

FxCop Custom Naming Rules

Recently I had started using FxCop,which is a wonderful code analysis tool.Soon after getting into it,I felt the need of rules specific to my requirements and standards.One such need was in the area of 'Naming of Variables'.
Every project/organization might have their own naming standards and rules for variables. FxCop provides a way to make sure everyone in the team adheres to these rules.
I found this material quite interesting and helpful.
FxCop And Code Analysis

FxCop analyzes the CIL( Common Intermediate Language) ,so it is supposedly to be language independent.The CIL genarated by the vb compiler and the c# compiler are almost same,but there are diferences which needs to be handled and taken care of while writing custom rules.
One such example i faced in checking for naming convention of string variables is posted here.

You can always see the CIL genarated using the 'ildasm' tool which comes with visual studio.
It would be helpful ,if you look at the IL genarated while writing rules,as writing rules is always a trial and error method.
One other tool which comes handy is Reflector.

Will soon post more on writing custom rules.Hope this helps to start with!!!!