我正在寻找这种行为:
<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点击它之后没有进行检查的时候,按钮的原因,因为我希望当用户点击时,View Model会做一些工作,如果一切正常,然后它将更新Checkbox的IsChecked标志。
答案 0 :(得分:0)
你的问题是你的模板。这没有任何意义。
你可能想做这样的事情:
<Button Content="Click me" Width="80" Height="20" Command="{Binding CreateButtonCommand}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<CheckBox Content="{Binding Path=Name}" Grid.Column="0" IsHitTestVisible="false" IsChecked="{Binding Path=IsChecked, Mode=OneWay}"/>
<ContentPresenter Grid.Column="1">
</ContentPresenter>
<Rectangle Fill="Transparent" Opacity="1" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Grid.ColumnSpan="2">
<Rectangle.InputBindings>
<MouseBinding Command="{TemplateBinding Command}"></MouseBinding>
</Rectangle.InputBindings>
</Rectangle>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>