如何覆盖风格 [英] How to overwrite a style

查看:188
本文介绍了如何覆盖风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用从扩展WPF工具包的DecimalUpDown控制在我的WPF应用程序ModernUI:



 < xctk:DecimalUpDown值={结合myProperty的} 增量=1最大=10最小=0/> 



我是什么错误这样的:如果选择强调色,比如红色,那么标准ModernUI-控件,如文本框适应那种颜色很好:





DecimalUpDown控制然而坚持它的风格。例如,控制是蓝色的,当它处于活动状态并在控制中使用的RepeatButtons并不像ModernUI按钮:





更糟糕的是:在全部查看文本框,其中DecimalUpDown控制将立即出现此风格,以蓝色,而不是红色突出显示:





我怎样才能改变这种状况?



编辑:这是生成的控件模板时,我跟本是个好建议:

 <控件模板X:键=ControlControlTemplate1的TargetType = {X:类型控制}> 
< xctk:ButtonSpinner X:NAME =PART_SpinnerAllowSpin ={结合AllowSpin,的RelativeSource = {的RelativeSource TemplatedParent}}
...>
< xctk:WatermarkTextBox X:NAME =PART_TextBoxAutoMoveFocus ={结合AutoMoveFocus,的RelativeSource = {的RelativeSource TemplatedParent}}
AutoSelectBehavior ={结合AutoSelectBehavior,的RelativeSource = {的RelativeSource TemplatedParent}}
AcceptsReturn =FALSE
... />
< / xctk:ButtonSpinner>
< ControlTemplate.Triggers>

< /ControlTemplate.Triggers>
< /控件模板>



它当时可能的样式化WatermarkTextBox和ButtonSpinner:





我至今没有管理:是否有访问ButtonSpinner内RepeatButtons的方式,这样我就可以设置自己的风格,以及


解决方案

大概汇入作业需要编写自己的模板,定义颜色出现。有时是改变它们在UI元素的部分性能没有直接的方法。
尝试编辑模板的复制和搜索蓝色值。
右键单击DecimalUpDown并转到编辑模板



如果颜色值是没有固定在那里,通过汇入作业的System.Colors(如ActiveBorderBrush)



<$设置可能汇入作业p $ p> <的SolidColorBrush X:键={X:静态SystemColors.ActiveBorderBrush}颜色=橙色/>



System.Colors定义一些标准品行当控制处于活动状态,高亮等MSDN列出所有现有的:
https://msdn.microsoft.com/en-us/library/system.windows.systemcolors%28v=vs.110%29.aspx


I use the DecimalUpDown control from the Extended WPF Toolkit in my WPF ModernUI app:

<xctk:DecimalUpDown Value="{Binding myProperty}" Increment="1"  Maximum="10" Minimum="0" />

What bugs me is this: If an accent color is selected, for example red, then standard ModernUI-Controls such as textboxes adapt that color nicely:

The DecimalUpDown control however sticks to its style. For example, the control is blue when it is active and the RepeatButtons used in the control do not look like ModernUI buttons:

Even worse: all TextBoxes in the View where the DecimalUpDown control is placed now exhibit this style and are highlighted in blue instead of red:

How can I change that?

EDIT: this is the generated ControlTemplate when I follow Ben's good advice:

        <ControlTemplate x:Key="ControlControlTemplate1" TargetType="{x:Type Control}">
        <xctk:ButtonSpinner x:Name="PART_Spinner" AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}" 
                            ...>
            <xctk:WatermarkTextBox x:Name="PART_TextBox" AutoMoveFocus="{Binding AutoMoveFocus, RelativeSource={RelativeSource TemplatedParent}}" 
                                   AutoSelectBehavior="{Binding AutoSelectBehavior, RelativeSource={RelativeSource TemplatedParent}}" 
                                   AcceptsReturn="False" 
                                   .../>
        </xctk:ButtonSpinner>
        <ControlTemplate.Triggers>
            ...
        </ControlTemplate.Triggers>
    </ControlTemplate>

It's then possible to style the WatermarkTextBox and the ButtonSpinner:

What I have not managed so far: Is there a way to access the RepeatButtons inside the ButtonSpinner, so that I can set their styles as well?

解决方案

It´s probably necessary to write your own template and define the color there. Sometimes there is no direct way to change properties which are part of the UI-element. Try to edit a copy of the template and search for the blue color value. Right click the DecimalUpDown and go to edit template

If the color value is no set there, it´s possible it´s set via the System.Colors (e.g. ActiveBorderBrush)

<SolidColorBrush x:Key="{x:Static SystemColors.ActiveBorderBrush}" Color="Orange" />

The System.Colors define some standard behavious when a control is active, highlighted, etc. MSDN lists all existing ones: https://msdn.microsoft.com/en-us/library/system.windows.systemcolors%28v=vs.110%29.aspx

这篇关于如何覆盖风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆