
I am dynamically building the content of an ExplorerBar, and I was hoping that there was already some clever way to bind to a resource and use data templates to construct the menu items and Expanders.
I tried the following (some snippage has occurred):
-----------------------
<Window.Resources>
<DataTemplate x:Key="ExpItem">
<TextBlock Text="{Binding XPath=@name}"/>
</DataTemplate>
<DataTemplate x:Key="Exp">
<shared:AnimatedExpander IsExpanded="True" Header="{Binding XPath=@name}">
<ItemsControl ItemsSource="{Binding XPath=b}"
ItemTemplate="{StaticResource ExpItem}"/>
</shared:AnimatedExpander>
</DataTemplate>
</Window.Resources>
<Grid>
<ItemsControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Grid.Column="0" Grid.Row="0" x:Name="MyExplorerBar"
ItemsSource="{Binding Source={StaticResource SomeXmlData}, XPath=/Menu/a}"
ItemTemplate="{StaticResource Exp}"/>
</Grid>
-----------------
This works. But if I replace ItemsControl with nav:ExplorerBar, it turns up empty. Is there some other way?
I tried the following (some snippage has occurred):
-----------------------
<Window.Resources>
<DataTemplate x:Key="ExpItem">
<TextBlock Text="{Binding XPath=@name}"/>
</DataTemplate>
<DataTemplate x:Key="Exp">
<shared:AnimatedExpander IsExpanded="True" Header="{Binding XPath=@name}">
<ItemsControl ItemsSource="{Binding XPath=b}"
ItemTemplate="{StaticResource ExpItem}"/>
</shared:AnimatedExpander>
</DataTemplate>
</Window.Resources>
<Grid>
<ItemsControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Grid.Column="0" Grid.Row="0" x:Name="MyExplorerBar"
ItemsSource="{Binding Source={StaticResource SomeXmlData}, XPath=/Menu/a}"
ItemTemplate="{StaticResource Exp}"/>
</Grid>
-----------------
This works. But if I replace ItemsControl with nav:ExplorerBar, it turns up empty. Is there some other way?