I have a WPF window that should load two vector images from XAML files. (Each is in a separate file for easier modification in Expression Design.)
When I include XAML files in MergedDictionary
, it works fine. Here is the code I'm using:
<Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Images/LCCD logo.xaml" /> <ResourceDictionary Source="Images/LCCD bottom image.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources>
and
<Image Source="{Binding Source={StaticResource LCCDlogo}}" /> <Image Source="{Binding Source={StaticResource LCCDbar}}" />
However, now I need to add more Window resources. The new resource belongs to this window, so we want it to be in the same file, and not in the included file.
When I add the following code between <Window.Resources>
and <ResourceDictionary>
, I get the following error:
the code
<Style TargetType="{x:Type tab:FabTabItem}"> <Setter Property="Header" Value="{Binding Path=LabelText}"/> <Setter Property="HeaderTemplate"> <Setter.Value> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,0,4,0"> <TextBlock Text="{Binding}" TextTrimming="CharacterEllipsis"/> </StackPanel> </DataTemplate> </Setter.Value> </Setter> </Style>
Attention
The designer does not support loading dictionaries that mix ResourceDictionary elements without a key and other elements in the same collection. Verify that the Resource property does not contain keyless ResourceDictionary elements or that the 'ResourceDictionary' element is the only element in the collection.
So, I am changing the <ResourceDictionary>
to this:
<ResourceDictionary x:Key="Images">
However, I do not know how to access the resources inside this dictionary now. How do you get resources from the name ResourceDictionary
?
EDIT
Nothing. It compiles, but does not start.
Error:
'' The resource property is already set to 'MainWindow'.
I think I have to do it differently.