简体   繁体   English

WPF多个字典,可进行单个控制

[英]WPF Multiple dictionaries for single control

I have one button control for which i have associated one dictionary, In that dictionary i have change the control template of the Button control but now on different screen i don't want to applied that dictionary on Button control i want to change the template. 我有一个与之相关联的词典的按钮控件,在该词典中,我更改了Button控件的控件模板,但是现在在不同的屏幕上,我不想将该词典应用于Button控件,我想更改模板。 How this thing can be achievable? 这件事怎么可以实现?

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" >

   <Style TargetType="{x:Type Button}">
    Some control template changes

   </Style>

Thanks 谢谢

It looks like you defined a style for a button. 看起来您为按钮定义了样式。 You want this style applied to button on Screen1. 您希望将此样式应用于Screen1上的按钮。

But for the button in screen2 you dont want to apply the same style. 但是对于screen2中的按钮,您不想应用相同的样式。

Applying the style for all buttons, it depends on what is the scope of your resource dictionary. 对所有按钮应用样式,这取决于资源字典的范围。 If its application scope the style will be applied to all buttons in all screens. 如果适用范围,则该样式将应用于所有屏幕中的所有按钮。

<Application.Resources> <ResourceDictionary Source="MyResourceDictionary.xaml" /> </Application.Resources>

If you want the style to specific to screen 1, create this dictionary only in screen1 user control so that scope will remain to only for that user control like... 如果您想要特定于屏幕1的样式,则仅在screen1用户控件中创建此词典,以便范围仅保留给该用户控件,例如...

<Usercontrol.Resources> <ResourceDictionary Source="MyResourceDictionary.xaml" /> <userControl.Resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM