如何自定义Extended WPF Toolkit中IntegerUpDown控件内的ButtonSpinner控件?

huangapple go评论63阅读模式
英文:

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>

如何自定义Extended WPF Toolkit中IntegerUpDown控件内的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>

如何自定义Extended WPF Toolkit中IntegerUpDown控件内的ButtonSpinner控件?

它看起来仍然一样。我漏掉了什么吗?

英文:

Sorry I'm pretty newbie in WPF styling. I have this ButtonSpinner control and I set its width and height using the appropriate properties:

    &lt;xctk:ButtonSpinner Width=&quot;200&quot; SpinnerWidth=&quot;100&quot; SpinnerHeight=&quot;100&quot;&gt;
    &lt;/xctk:ButtonSpinner&gt;

如何自定义Extended WPF Toolkit中IntegerUpDown控件内的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) :

&lt;xctk:IntegerUpDown Value=&quot;1564&quot; Width=&quot;200&quot; Height=&quot;100&quot;&gt;
        &lt;xctk:IntegerUpDown.Resources&gt;
            &lt;Style TargetType=&quot;{x:Type xctk:ButtonSpinner}&quot;&gt;
                &lt;Setter Property=&quot;SpinnerWidth&quot; Value=&quot;100&quot;/&gt;
                &lt;Setter Property=&quot;SpinnerHeight&quot; Value=&quot;100&quot;/&gt;
            &lt;/Style&gt;
        &lt;/xctk:IntegerUpDown.Resources&gt;
&lt;/xctk:IntegerUpDown&gt;

如何自定义Extended WPF Toolkit中IntegerUpDown控件内的ButtonSpinner控件?

It still looks the same. Am I missing something?

答案1

得分: 0

无需翻译的代码部分已被去除,以下是翻译的内容:

一个隐式添加到控件的Resources属性的Style是否应用于该控件的子元素取决于该控件的模板定义方式。

如果模板明确设置了子控件的Style属性,就像下面的示例一样,Resources中的隐式Style将不会被应用:

如果模板设置了子控件的依赖属性的本地值,您无法使用Style来设置该属性,因为本地值会优先于StyleSetter指定的值。

英文:

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:

&lt;ControlTemplate TargetType=&quot;{x:Type xctk:IntegerUpDown}&quot;&gt;
    ...
    &lt;xctk:ButtonSpinner Style=&quot;{StaticResource someCustomStyle}&quot; ... /&gt;

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.

huangapple
  • 本文由 发表于 2023年3月8日 16:32:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670823.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定