我使用了一个控件模板,以一种简单的方式更改按钮的外观。它现在看起来不同,但不像按钮那样。实际上有两个问题:
以下是一般概念:
<Button Command="{x:Static commands:...}"
CommandParameter="{Binding}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Ellipse Fill="{Binding ...}"
.../>
</ControlTemplate>
</Button.Template>
</Button>
答案 0 :(得分:2)
CommandBinding
无法正常工作。Fill="Green"
。您可以尝试在FocusVisualStyle="{x:Null}"
上设置Button
。答案 1 :(得分:1)
问题是Fill
被绑定到一个可能为null的值。如果Fill
画笔为空而不是透明,则没有任何内容可以单击,并且命令不会被执行。正如Drew所提到的,通过实心填充,按钮可以正常工作。
外卖课:如果你想隐藏你的形状但仍然让它响应用户互动,请使用透明刷,而不是空刷。
答案 2 :(得分:0)
我在自定义模板化按钮上遇到了类似的问题:
<my:UniButton Command="{Binding MyCommand}"/>
绑定在添加RelativeSource之前不起作用:
<my:UniButton Command="{Binding MyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=my:CustomPanel}}"/>
其中CustomPanel是我的按钮所在的控件。
Withal我在同一个面板上有一个简单的按钮,但即使没有RelativeSource也能正常工作。