Ho una finestra WPF che dovrebbe caricare due immagini vettoriali da file XAML. (Ciascuno è in un file separato per semplificare la modifica in Expression Design.)Ottenere una risorsa da un ResourceDictionary con una chiave
Quando includo i file XAML in un MergedDictionary
, funziona correttamente. ecco il codice che uso:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Images/LCCD logo.xaml" />
<ResourceDictionary Source="Images/LCCD bottom image.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
e
<Image Source="{Binding Source={StaticResource LCCDlogo}}" /> <!-- Simplified -->
<Image Source="{Binding Source={StaticResource LCCDbar}}" /> <!-- Simplified -->
Tuttavia, ora bisogno di aggiungere di più per le risorse della finestra. La nuova risorsa appartiene a questa finestra, quindi vogliamo che sia nello stesso file anziché in un file incluso.
Quando aggiungo il seguente codice tra <Window.Resources>
e <ResourceDictionary>
, ottengo il seguente errore:
Codice
<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>
Attenzione
The designer does not support loading dictionaries that mix 'ResourceDictionary' items without a key and other items in the same collection. Please ensure that the 'Resources' property does not contain 'ResourceDictionary' items without a key, or that the 'ResourceDictionary' item is the only element in the collection.
Così ho cambiare la <ResourceDictionary>
tag a questo:
<ResourceDictionary x:Key="Images">
Tuttavia, non so come accedere alle risorse all'interno di questo dizionario ora. Come si ottengono le risorse dall'interno di un numero ResourceDictionary
?
EDIT
Non importa. Questo compila ma non funziona.
L'errore è:
''Resources' property has already been set on 'MainWindow'.
mi sa che dovrò farlo in qualche altro modo.
Sembra che funzioni, ed è una risposta molto migliore che mia. –
@MosheKatz Felice di aiutare –