我需要基于 RedButtonStyle 创建名为 OkButtonStyle 的资源。 但我有带有 key 的资源,未找到异常。我做错了什么? 我有两个资源词典。 RedButtonStyle 位于的一个 baseStyles.xaml 和我需要找到 okbuttonstyle 的 styles.xaml,但我所有的努力都没有结果。
App.xaml
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="baseStyles.xaml" />
<ResourceDictionary x:Name="currentTheme" Source="styles.xaml" />
</ResourceDictionary.MergedDictionaries>
styles.xaml
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="baseStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="OkButtonStyle"
BasedOn="RedButtonStyle"
TargetType="Button">
</Style>
baseStyles.xaml
<Style x:Key="RedButtonStyle"
TargetType="Button">
...properties...
</Style>
最佳答案
而不是使用语法:
<Style BasedOn="RedButtonStyle" ...
使用语法:
<Style BasedOn="{StaticResource RedButtonStyle}" ...
Style.BasedOn
属性不是它所基于的其他样式的名称,它是它所基于的样式.
关于c# - 银光。无法从其他 xaml 资源设置基本样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004729/