【发布时间】:2016-11-22 18:22:43
【问题描述】:
我正在寻找这种行为:
<Button Command="{Binding Path=CreateButtonCommand}">
<Button.Content>
<CheckBox Content="{Binding Path=Name}" IsHitTestVisible="false"
IsChecked="{Binding Path=IsChecked, Mode=OneWay}"/>
</Button.Content>
</Button>
但我想要这个样子:
<Button Command="{Binding Path=CreateButtonCommand}">
<Button.Content>
<CheckBox Content="{Binding Path=Name}" IsHitTestVisible="false"
IsChecked="{Binding Path=IsChecked, Mode=OneWay}"/>
</Button.Content>
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
我在你点击它时 CheckBox 不呈现检查的地方,按钮的原因,因为我希望当用户点击时,视图模型会做一些工作,如果一切正常,那么它会更新 Checkbox 的 IsChecked 标志。
【问题讨论】:
-
如果您设置
IsHitTestVisible="false",则不会触发单个事件并且不会捕获鼠标。你不能点击那个复选框 -
好的,那么您的问题是什么?请提供一个良好的minimal reproducible example,该minimal reproducible example 可以可靠地重现您遇到的任何特定问题,并清楚、准确地描述该问题是什么。
-
如何让我的第二个代码示例触发按钮中定义的命令?
-
我正在努力完成 PaulMolly 从这篇文章中回复的内容:stackoverflow.com/questions/921921/…