我需要將應用程序樣式分隔爲幾個xaml文件。 但我也需要在單個文件在其他文件中定義的樣式定義一些共同的價值觀像winrt xaml合併資源
<x:Double x:Key="SharedValue">100</x:Double>
使用此值。 例如:
<Style x:Name="SomeStyle" TargetType="TextBox">
<Setter Property="Width" Value="{StaticResource SharedValue}"/>
</Style>
和其他資源字典文件:
<Style x:Name="AnotherStyle" TargetType="Button">
<Setter Property="Height" Value="{StaticResource SharedValue}"/>
</Style>
但當我嘗試定義在App.xaml中合併資源字典文件
<Application.Resources>
<ResourceDictionary >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DefinedValues.xaml"/>
<ResourceDictionary Source="Styles1.xaml"/>
<ResourceDictionary Source="Styles2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我得到這個運行異常:「消息=」找不到具有名稱/密鑰共享值的資源「
你能告訴我這樣做是否可行?我做錯了什麼? 謝謝。
你在哪裏看到信息?您是否試圖通過{StaticResource}訪問XAML中的資源? –
在App.g.i.cs文件中將它作爲運行時未處理的異常處理時出現此錯誤,但intelisence不會將我的SharedValue點亮爲任何地方無法識別的。 –
是的,這是可能的,我可以使用你的例子創建一個應用程序,它適用於我的項目。您確定您的App.xaml文件中有DefinedValues.xaml和另外兩個ResourceDictionaries的正確路徑嗎? –