Archive for the ‘WPF’ Category

ListView with Dynamic ContextMenu

March 18, 2008 6 comments

When we want to display a ContextMenu based on the ListViewItem(Row) that was clicked, we have to handle ContextMenuOpening event and add our menuitems in that event. Attached sample shows how to do this.(change .doc to .zip)

Categories: WPF Tags: , ,

ListView MasterDetail

March 11, 2008 9 comments

Here is a sample showing masterdetail using ListView


Here is a sample(rename .doc to .zip)

Categories: WPF

Handle Triple click

March 6, 2008 Leave a comment

if we ever want to do something when user triple clicks in/on the control, we can handle the PreviewMouseDown event and handle it like this

void ControlName_PreviewMouseDown(object sender, MouseButtonEventArgs e) 
  if (e.ClickCount == 3) 
Categories: WPF

Styling ComboBox- part 2

March 1, 2008 Leave a comment

Here is a sample to display multiple columns which are resizable, like in gridview in the panel of the combobox


 Attached is a sample(change .doc to .zip)


Categories: WPF Tags: ,

Styling ComboBox- part 1

February 28, 2008 3 comments

if we want to change the text that is displayed when user selects an item in the combobox, we have to change the ContentTemplate of the ContentPresenter in the Combobox Template


Attached is a sample(change .doc to .zip), which allows you to specify the template to be applied in the Tag property


(update: added a thumb to the panel, which lets you resize the panel)


Categories: WPF Tags: ,

Getting the text of the selecteditem in Combobox

February 26, 2008 9 comments

When you look at the Text property in the SelectionChanged event of the ComboBox it returns the prior value
here is a way to get the right value (cb1 is the name of the ComboBox)

Add this in Window loaded event

DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ComboBox.TextProperty, typeof(ComboBox));

dpd.AddValueChanged(cb1, OnTextChanged);

and here is the handler

private void OnTextChanged(object sender, EventArgs args)

Categories: WPF

Get every new post delivered to your Inbox.