定义新的 ControlTemplate 保留原始事件
我想使用 ExtendedWPFToolkits 的 ColorPicker,但使用自定义 ButtonStyle。 我可以创建一个覆盖项目的模板属性的新外观,但原始模板单击事件丢失。
我想保留它,但是怎么保留呢?
<Controls:ColorPicker >
<Controls:ColorPicker.ButtonStyle>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Button Content="ColorPicker"></Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Controls:ColorPicker.ButtonStyle>
</Controls:ColorPicker>
I want to use the ExtendedWPFToolkits's ColorPicker but with a custom ButtonStyle.
I can create a new look overriding the Template property of the item but the original templates click event is missing.
I want to keep it, but how?
<Controls:ColorPicker >
<Controls:ColorPicker.ButtonStyle>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Button Content="ColorPicker"></Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Controls:ColorPicker.ButtonStyle>
</Controls:ColorPicker>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的内容无效。您将一个
Button
放入ToggleButton
的 ControlTemplate 中,因此基本上是一个按钮中的按钮。您需要执行以下操作:
我添加了一个透明的边框,以便按钮能够接收文本未覆盖的区域的鼠标事件。
What you have is not valid. You are putting a
Button
in the ControlTemplate of aToggleButton
, so basically a button in a button.You'd need to do something like:
I added a transparent
Border
so the button will be able to receive mouse events for areas not covered by the text.