Searching for a Best DataTemplate knowledge in WPF and the Properties used in it?
I want brief knowledge about Data Template for Customizing a control(like Combo Box,List Box etc.)in WPF using C#.NET. So if anybody have any links or sample applications then share it with me please..
Update: I got to know the DataTemplate in some what but now I want to know about the terms used for DataTemplate like ObservableCollecti开发者_开发问答on,DataContext and how to set the Binding property according to the User's need. I want an idea for develop a very similar kind of Sample application like dividing Combo Box's each items into three Column and adding different contents on different columns dynamically
Thanks in Advance
here is it used very simply - but basically a DataTemplate allows you to represent data using XAML
<ItemsControl ItemsSource="{Binding Path=SomeDataCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=SomeProperty}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
You should check out the WPF Quiz demo : http://community.infragistics.com/pixel8/media/p/91950.aspx It will teach you MVVM and the power of DataTemplates in one go :)
Suppose you want to show the button in each item of ComboBox , so you can do this by overriding its ItemTemplate method
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<Button Content="Sa"></Button>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
and in the code behind
List<string> lst = new List<string>();
for (int i = 0; i < 5; i++)
{
lst.Add("Sa" + i.ToString());
}
cmb.ItemsSource = lst;
so now when you run this , you will get the desired output , each combo item will be a button
精彩评论