WPF 扩展器切换按钮 - 在设置器中解决它们?
您好,是否可以在 ExpanderStyle 的 Setter 中分配 ToggleButtonStyle? 就像这在日历中是可能的:
<Style x:Key="CS" TargetType="{x:Type Calendar}" >
<Setter Property="CalendarDayButtonStyle" Value="{StaticResource CalendarDayButtonStyle}"/>
<Setter Property="CalendarButtonStyle" Value="{StaticResource CalendarButtonStyle}"/>
<Setter Property="CalendarItemStyle" Value="{StaticResource CalendarItemStyle}"/>
</Style>
问题背景:在 BasedOn-Styles 中,我只更改设置器,而不是整个模板进行小的更改。
多谢。
Hi is it possible to assign a ToggleButtonStyle in a Setter in the ExpanderStyle?
Like this is possible in the Calendar:
<Style x:Key="CS" TargetType="{x:Type Calendar}" >
<Setter Property="CalendarDayButtonStyle" Value="{StaticResource CalendarDayButtonStyle}"/>
<Setter Property="CalendarButtonStyle" Value="{StaticResource CalendarButtonStyle}"/>
<Setter Property="CalendarItemStyle" Value="{StaticResource CalendarItemStyle}"/>
</Style>
Background of the question: In BasedOn-Styles i only change the setter and not the whole template for small changes.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是不可能开箱即用的。可能是因为没有一种
ToggleButton
样式,所以有四种,每种ExpandDirection
可能对你来说有点过头了,但如果你真的需要这个功能可重用,你可以创建自己的自定义控件,其中您添加四个依赖项属性:
ToggleButtonDownStyle
、ToggleButtonUpStyle
、ToggleButtonLeftStyle
和ToggleButtonRightStyle
并复制的默认样式Expander
为自定义控件的默认样式,但将ToggleButton
样式的 StaticResource 更改为TemplateBinding
所以这并不容易,但这可以让你做你想做的事情(我猜你最感兴趣的是默认的
Down
方向)以下是控件的外观,我将其命名为
StyleableExpander
并将其放入“WPF 自定义控件库”中以实现可重用性。仅出于演示目的添加了ToggleButtonDownStyle
这里是(非常详细的)具有默认样式的
Generic.xaml
。ToggleButton
的 StaticResource 已更改为{TemplateBinding ExpanderDownHeaderStyle}
。要获取所有四个方向,您还需要更改ExpandDirection
的触发器This is not possible out-of-the-box. Probably because there isn't one
ToggleButton
Style, there is four, one for eachExpandDirection
Probably overkill for you but if you really need this functionality to be reusable you could create your own custom control where you add four Dependency Properties,
ToggleButtonDownStyle
,ToggleButtonUpStyle
,ToggleButtonLeftStyle
andToggleButtonRightStyle
and copy the default style forExpander
into the default Style for your custom control but change the StaticResource forToggleButton
Style to aTemplateBinding
So it doesn't come easy but this would allow you to do what you're after (and I'm guessing you're mostly interested in the default
Down
direction)Here is how to control could look, I named it
StyleableExpander
and put it in a "WPF Custom Control Library" for reusability. Only addedToggleButtonDownStyle
for demo purposeAnd here is (the very verbose)
Generic.xaml
with the default style. StaticResource for theToggleButton
has been changed to{TemplateBinding ExpanderDownHeaderStyle}
. To get all four directions you would need to change the triggers forExpandDirection
as well不,这是不可能的。 Expander 控件不公开该属性。但是,您可以设置扩展器模板并以您想要的任何方式显示该按钮。
这是默认模板的完整 XAML 代码
您应该复制该模板添加到您的项目并修改 ToggleButton 以使用您想要的任何样式:
No, it's not possible. The Expander control does not expose that property. However you can set the expander template and show that button in any way you want.
Here is the complete XAML code for the default template
You should copy that template to your project and modify the ToggleButton to use any style you want: