仅重新设计 wpf 控件的一部分。 是否可以?
我只想重新设计 WPF 控件的一部分。
(具体来说,我想让 ScrollBar 上的滚动按钮更大)
现在我可以毫无问题地做到这一点。 我提取了默认样式。 进行了所需的调整并将修改后的样式包含在我的应用程序中。
问题是,当我更改的只是 2 个值时,我必须在替换样式中包含整个控件模板。
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="ScrollBar">
<Grid Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
<ColumnDefinition Width="1E-05*" />
<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
</... etc
我只想将列定义上的 MaxWidth 更改为 50。
所以我的问题是:有什么方法可以对模板进行此调整,而不必包含其他所有内容? 我仍然希望控件模板的所有其他部分都像默认值一样工作。
I want to restyle just part of a WPF control.
(Specifically, I want to make the scroll buttons on a ScrollBar bigger)
Now I can do this no problem. I extracted the default style. Made the required tweaks and included the modified style in my application.
The problem is that I have to include the entire control template in the replacement style, when all I am changing is 2 values.
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="ScrollBar">
<Grid Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
<ColumnDefinition Width="1E-05*" />
<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
</... etc
I just want to change the MaxWidth on the column definitions to 50.
So my question is this: Is there any way I can make this tweak to the template without having to include everything else? I still want all other parts of the control template to just work like the default.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您应该能够这样做,因为模板会伸出援手并从资源中获取值:
如果模板对值进行了硬编码,那么您就不走运了。
In this case you should be able to, since the template reaches out and grabs the value from a resource:
If the template had hard-coded the value, you'd be out of luck.