使用带有键的样式从一个装配到另一个装配 [英] Using Style with Key from one assembly to another one
问题描述
您好,
我在xaml文件中有一个ResourceDictionary" res_xaml"出现在程序集ResourceControl.dll中。该资源字典在文件"generic.xaml"中使用ResourceDictionary.MergedDictionaries合并。在与上面相同的组件中。最终
我可以在我的WPF表单中使用res_xaml文件中的所有样式。
现在有一个有密钥的样式。我想使用"BasedOn"这种风格。在我的WPF表格中。下面的代码是我的WPF表格。
< Style TargetType =" {x:Type myStyle}" BasedOn =" {DynamicResource myKey}">
< / Style
在上面的代码"myKey"中是res_xaml文件中存在的样式的关键。我收到一个错误,说它无法找到此密钥。我尝试使用StaticResource但它也没有用。
谢谢,
Abdi
您好abdi1234,
您需要为您的风格指定"x:Key",例如以下:
< Style x:Key =" mystyle" TargetType =" {x:Type myStyle}" BasedOn =" {StaticResource myKey}">
< / Style最好的问候,
Xavier Xie
Hello,
I have a ResourceDictionary in a xaml file "res_xaml" present in an assembly ResourceControl.dll. This resourcedictionary is merged using ResourceDictionary.MergedDictionaries in a file "generic.xaml" in the same assembly as above. Ultimately I am then able to use all the styles present in res_xaml file in my WPF forms.
Now there is style which has a key. I want to use this style using "BasedOn" in my WPF Form. Below code is in my WPF Form.
<Style TargetType="{x:Type myStyle}" BasedOn="{DynamicResource myKey}"> </Style
In above code "myKey" is a key of the style present in res_xaml file. I am getting an error saying that it is unable to locate this key. I tried using StaticResource but it also did not worked.
Thanks,
Abdi
Hi abdi1234,
You need to specify a "x:Key" for your style like the following:
<Style x:Key="mystyle" TargetType="{x:Type myStyle}" BasedOn="{StaticResource myKey}"> </StyleBest Regards,
Xavier Xie
这篇关于使用带有键的样式从一个装配到另一个装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!