Access an array item (in ResourceDictionary) in xaml
Posted: 26 Aug 2023, 15:55
Hello there.
I have an array of images, defined in ResourceDictionary, like this:
I have a window, where I want to show one of that icons, by bindig a variable.
Just for test I tried to get index 0:
But it shows an error XDG-0001. How can I do it right? (I guess it's something trivial, but I'm a newbie in xaml)
I have an array of images, defined in ResourceDictionary, like this:
Code: Select all
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Array x:Key="NotificationIcons" Type="Path">
<Path Name="ErrorIcon" Fill="#FFFF4040">
...
</Path>
<Path Name="InfoIcon" Fill="#ffffff">
...
</Path>
<Path Name="WarningIcon" Fill="#FFFFFF40">
...
</Path>
</x:Array>
</ResourceDictionary>Just for test I tried to get index 0:
Code: Select all
<StackPanel Orientation="Horizontal">
<Canvas Name="Icon" Width="36" Height="36" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,0,0">
<ContentControl Content="{Binding Source={StaticResource NotificationIcons[0]}}"/>
</Canvas>
<TextBlock x:Name="Message" VerticalAlignment="Center" Foreground="White" Padding="10,10,10,10" Text="{Binding Message}"/>
</StackPanel>