英文:
How to customize ButttonSpinner control inside an IntegerUpDown control in Extended WPF Toolkit?
问题
抱歉,我只会翻译文本,不会执行代码。以下是您提供的文本的翻译:
抱歉,我在WPF样式方面还很新手。我有一个ButtonSpinner控件,我使用适当的属性设置了它的宽度和高度:
<xctk:ButtonSpinner Width="200" SpinnerWidth="100" SpinnerHeight="100">
</xctk:ButtonSpinner>
如您所见,向上的旋转按钮和向下的旋转按钮的宽度和高度都会相应增加。
但是,为什么当应用到IntegerUpDown控件内的ButtonSpinner时,我无法做同样的事情?(IntegerUpDown主题: https://github.com/xceedsoftware/wpftoolkit/blob/master/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/NumericUpDown/Themes/Generic.xaml):
<xctk:IntegerUpDown Value="1564" Width="200" Height="100">
<xctk:IntegerUpDown.Resources>
<Style TargetType="{x:Type xctk:ButtonSpinner}">
<Setter Property="SpinnerWidth" Value="100"/>
<Setter Property="SpinnerHeight" Value="100"/>
</Style>
</xctk:IntegerUpDown.Resources>
</xctk:IntegerUpDown>
它看起来仍然一样。我漏掉了什么吗?
英文:
Sorry I'm pretty newbie in WPF styling. I have this ButtonSpinner control and I set its width and height using the appropriate properties:
<xctk:ButtonSpinner Width="200" SpinnerWidth="100" SpinnerHeight="100">
</xctk:ButtonSpinner>
And it works as you see the up spinner and down spinner width and height are increased accordingly.
But why I cannot do the same when applying it to the ButtonSpinner inside IntegerUpDown control? (IntegerUpDown theme: https://github.com/xceedsoftware/wpftoolkit/blob/master/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/NumericUpDown/Themes/Generic.xaml) :
<xctk:IntegerUpDown Value="1564" Width="200" Height="100">
<xctk:IntegerUpDown.Resources>
<Style TargetType="{x:Type xctk:ButtonSpinner}">
<Setter Property="SpinnerWidth" Value="100"/>
<Setter Property="SpinnerHeight" Value="100"/>
</Style>
</xctk:IntegerUpDown.Resources>
</xctk:IntegerUpDown>
It still looks the same. Am I missing something?
答案1
得分: 0
无需翻译的代码部分已被去除,以下是翻译的内容:
一个隐式添加到控件的Resources
属性的Style
是否应用于该控件的子元素取决于该控件的模板定义方式。
如果模板明确设置了子控件的Style
属性,就像下面的示例一样,Resources
中的隐式Style
将不会被应用:
如果模板设置了子控件的依赖属性的本地值,您无法使用Style
来设置该属性,因为本地值会优先于Style
的Setter
指定的值。
英文:
Whether an implicit Style
that you add to the Resources
property of a control is applied to a child element of that control depends on how the template for control is defined.
If the template explicitly sets the Style
property of the child control as in the example below, the implicit Style
in Resources
won't be applied:
<ControlTemplate TargetType="{x:Type xctk:IntegerUpDown}">
...
<xctk:ButtonSpinner Style="{StaticResource someCustomStyle}" ... />
Also, if the template sets the local value of a dependency property of a child control, you cannot set this property using a Style
as the local value takes precedence over a value specified by a Setter
of a Style
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论