Why can't I use Telerik's RadPanelBar with a standard collection of objects?
I am trying to use Telerik's RadPanelBar to display a list of objects. I would like the name to display when it is collapsed, and the object to display when expanded. For some reason this doesn't seem to work. Am I using this control incorrectly??
<telerik:RadPanelBar ItemsSource="{Binding Contacts}" />
The Control renders correctly, with the correct number of items, however I cannot expand any of the items. I would like this to render as something like:
<Item Header="{Binding开发者_Python百科 Name}" IsExpanded="False" />
<Item Header="{Binding Name}" IsExpanded="True">
<ContentControl Content="{Binding }" />
</Item>
<Item Header="{Binding Name}" IsExpanded="False" />
<Item Header="{Binding Name}" IsExpanded="False" />
For whatever reason, the RadPanelBar needs to be bound to a collection within a collection. It doesn't work with a single object. A workaround I use is this:
<telerik:RadPanelBar ItemsSource="{Binding Contacts}">
<telerik:RadPanelBar.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding ObnoxiousWorkaroundForTelerik}">
<TextBlock Text="{Binding Name}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding }" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</telerik:RadPanelBar.ItemTemplate>
</telerik:RadPanelBar>
In my ContactClass I added a collection just for this....
private ObservableCollection<AgencyContact> _forTelerik;
public ObservableCollection<AgencyContact> ObnoxiousWorkaroundForTelerik
{
get
{
if (_forTelerik == null)
{
_forTelerik = new ObservableCollection<AgencyContact>();
_forTelerik.Add(this);
}
return _forTelerik;
}
}
If someone knows of another workaround that doesn't require me to create a collection of my class within my class please let me know!
I don't have experience with this control in particular, but I know that in other WPF controls if you are trying to display something that expands and collapses you need to define a HierarchicalDataTemplate. See: http://msdn.microsoft.com/en-us/library/system.windows.hierarchicaldatatemplate.aspx or for a more step by step approach see here: http://blogs.msdn.com/b/mikehillberg/archive/2009/10/30/treeview-and-hierarchicaldatatemplate-step-by-step.aspx.
Looking on the Telerik forum it looks like this post has an example of doing this: http://www.telerik.com/community/forums/wpf/panelbar/radpanelbar-datatemplate.aspx
精彩评论