Monday, January 18, 2010

Designing a Button in WPF - "Simplest yet cool Button"

Hi All,

I have seen a lot of button templates which offer a cool looking styles by overriding the complete button template. Just to give a small style to a button can be complicated as far as overriding the template is concerned. I tried to build a button something like this :



An option could be, to include a new style for my button and override the template. But do we really need to do that???? I don't think so. The button which you are seeing in the Image is actually not a button, it is actually a border object filled with Alice Blue color, and with the corner radius set to 5. There is a textblock object inside the border so that it can contain some text. I didn't use label for that because textblock is lighter than a label.




Now, this control is not yet completed because it doesn't give any notification whenever it is clicked. So I had to include some animation to this button.




Here, I have opted to use code behind to run my animation. Like shown in the figure below :




After including the above code lines, you can see that the border looks like a button and animates as well once you click the control.

HTH,
Vikas

Thursday, October 8, 2009

WPF : Changing Listview Selected Item color

Hi All,

I am really loving WPF these days, all of the things which looked really tough to me earlier, are not simplified using WPF XAML.

Here is the code for changing the background color of the selected item in a listview :
Code :



< Style TargetType="ListViewItem">
< Style.Resources>
< SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="WhiteSmoke"/>
< SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>




Thanks,
Vikas

Saturday, August 29, 2009

Binding Checkbox with the Listview Item Selection

Hi All,

I know, lot of people juggle around for this. I also did ;)

Have you ever wondered to have a checkbox in a listview item which should be checked/unchecked as per the listviewitem selection and vice versa?

Suppose if you have a checkbox as a listview item, and you want to check/uncheck the checkbox as soon as user selects the listview item. And vice versa, the listview item should be selected as soon as user selects the checkbox. The following line solves this purpose :



HTH,
Vikas Bhandari

Formatting the GridView Column Header in Listview

Hi All,

Please find below the code to set the background color of a GridviewColumnHeader inside a Listview. I will add more to it ;)



Code to set the font size of a GridviewColumnHeader :



Thanks,
Vikas