I created 2 image resources and I want to dynamically reference them from within the HierarchicalDataTemplate of the TreeView control.
This is my XAML code:
<TreeView Margin="17,22" Name="TreeView">
<TreeView.Resources>
<BitmapImage x:Key="Icon1" UriSource="pack://application:,,,/icon1.ico"/>
<BitmapImage x:Key="Icon2" UriSource="pack://application:,,,/icon2.ico"/>
</TreeView.Resources>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource Icon1}" Margin="0,0,5,0" Width="16" Height="16"/>
<TextBlock Text="{Binding Name}" Margin="0,2,0,0" FontWeight="Normal" FontSize="11"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
What is the correct syntax for attaching a source to an image so that I can select a static image at runtime?
Chris source
share