के साथ संसाधन प्राप्त करें मेरे पास एक WPF विंडो है जो XAML फ़ाइलों से दो वेक्टर छवियों को लोड करना है। (अभिव्यक्ति डिज़ाइन में आसान संशोधन के लिए प्रत्येक एक अलग फ़ाइल में है।)एक संसाधन 0 से एक संसाधन
जब मैं MergedDictionary
में XAML फ़ाइलों को शामिल करता हूं, तो यह ठीक काम करता है।
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Images/LCCD logo.xaml" />
<ResourceDictionary Source="Images/LCCD bottom image.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
और
<Image Source="{Binding Source={StaticResource LCCDlogo}}" /> <!-- Simplified -->
<Image Source="{Binding Source={StaticResource LCCDbar}}" /> <!-- Simplified -->
हालांकि, मैं अब खिड़की के संसाधनों के लिए और अधिक जोड़ने की जरूरत: यहाँ कोड मैं का उपयोग करें। नया संसाधन इस विंडो से संबंधित है, इसलिए हम इसे एक फ़ाइल में शामिल फ़ाइल के बजाय एक ही फाइल में रखना चाहते हैं।
जब मैं <Window.Resources>
और <ResourceDictionary>
के बीच निम्न कोड जोड़ने के लिए, मैं निम्नलिखित त्रुटि हो:
कोड
<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>
चेतावनी
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.
तो मैं <ResourceDictionary>
बदल इसे टैग करें:
<ResourceDictionary x:Key="Images">
हालांकि, मुझे नहीं पता कि अब इस शब्दकोश के अंदर संसाधनों का उपयोग कैसे किया जाए। आप नाम ResourceDictionary
के अंदर से संसाधन कैसे प्राप्त करते हैं?
संपादित
कोई बात नहीं। यह संकलित करता है लेकिन नहीं चलता है।
त्रुटि है:
''Resources' property has already been set on 'MainWindow'.
मुझे लगता है कि मैं इसे किसी अन्य तरीके से करना होगा।
ऐसा लगता है कि यह काम करता है, और यह मेरा एक बेहतर जवाब है। –
@MosheKatz मदद करने के लिए खुशी हुई –