Tuesday, July 24, 2007

Using ListView as DataGrid with the help of GridView

There is no native Data Grid in WPF.But we could achieve the behaviour with the help of ListView and GridView.

ListView has a property called View.Set a GridView to that property to get data displayed as DataGrid

Basic details
Sort columns upon header click

Workarounds
Control column width upon dragging

Wednesday, July 18, 2007

Host WPF controls in Windows forms & viceversa

Host WPF controls in windows forms

Host Windows forms controls in WPF

Better host winforms control into UserControl and then host that UserControl into WPF.So we wont lose designer facilities of windows forms control

Tuesday, July 17, 2007

Download MS Expression books

  1. Microsoft Expression Web For Dummies

Monday, July 2, 2007

Simple filtering in ListBox / CollectionView

The following code snippet will allow you to filter out unwanted items from your collection.

<Grid Name ="grd">
<Grid.Resources>
<XmlDataProvider x:Key="Company" XPath="/Company">
<x:XData>
<Company xmlns="">
<Person Name="Jack" Role="CEO"/>
<Person Name="Tim" Role="PL" />
<Person Name="Jil" Role="PL" />
<Person Name="Jimmy" Role="PM" />
<Person Name="Joy" Role="PM" />
<Person Name="Jim" Role="PL" />
<Person Name="Jack" Role="PM" />
</Company>
</x:XData>
</XmlDataProvider>
<DataTemplate x:Key="template">
<TextBlock Text="{Binding XPath=@Name}"/>
</DataTemplate>
<CollectionViewSource x:Key="cvs" Source="{Binding Source={StaticResource Company},XPath=Person}"
Filter="src1_Filter"/>
</Grid.Resources>
<ListBox Name="lst"
ItemTemplate="{StaticResource template}"
ItemsSource="{Binding Source={StaticResource cvs}}"/>
</Grid>

//Filter method
void src1_Filter(object sender, FilterEventArgs e)
{
System.Xml.XmlElement ele=e.Item as System.Xml.XmlElement;
string name=ele.Attributes[0].Value ;
if (name == "Tim") e.Accepted = true;
else e.Accepted = false;
}

This will display item "Tim".You may do custom filtering as you like in the filter method