我在一個名爲ItemsTemplate
的單獨項目中有一個資源字典。來自不同項目的資源字典拋出異常
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type TextBox}"
x:Key="TextBoxesTemplate"
>
<Setter Property="OverridesDefaultStyle"
Value="True"/>
<Setter Property="Margin"
Value="5"/>
<Setter Property="BorderThickness"
Value="1"></Setter>
</Style>
</ResourceDictionary>
我想在許多不同的項目中使用它。而我拋出一個異常,當我運行它,說: 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.'
所以這裏是我執行什麼我曾嘗試:
和
<ResourceDictionary Source="/ItemTemplates;component/Style.xaml"></ResourceDictionary>
和
<TextBox Style="{StaticResource TextBoxesTemplate}"
Grid.Row="0"
Grid.Column="2"
Text="{Binding SelectedModel.Code}"/>
我試圖改變
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ItemTemplates;component/Style.xaml">
</ResourceDictionary.MergedDictionaries>
和
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ItemTemplates;component/Style.xaml">
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack:application,,,/ItemTemplates;component/Style.xaml">
</ResourceDictionary.MergedDictionaries>
注:這是.NET 4.5.2
編輯:建立用這個。但仍然得到例外
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ItemTemplates;component/Style.xaml"
x:Name="SDictionary" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
我猜你正在設置你的字典內的資源標籤?像然後你的合併字典 –
adminSoftDK
是的,我使用的是。資源 – JamTay317