Reputation: 3
I´m a beginner in WPF and XAML Programming. And my English isn't very good. Sorry for that!
Here is my Problem. I want a custom Check-box. It should only be enabled when the Mouse is over and the Cursor should change to the Help-Cursor.
That works fine! When i click in the Check-box, the Check-box changes to .ischeckd = true
and shows the litte arrow in the check-box. When i click again in the check-box the .ischecked
property changes to false
an the little arrow in the Check-box is gone. So far so good!
But when I set the .ischeckd Value Programaticaly it doesn't changes the little arrow in the Check-box. So the User of the Program thinks the Check-box is "active" even though the .ischecked property is false. Hope you understand my Problem...
Here is the XAML Code:
</Style>
<Storyboard x:Key="StoryboardCheckBox"/>
<Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Grid Margin="0,0,42,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="checkBox">
<DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<CheckBox x:Name="checkBox" Content="Gutschrift" FontSize="13.333" IsEnabled="False" Cursor="Help" Margin="0,0,4.937,0"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="" Margin="78.063,9.723,0,0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
... some lables and buttons and other stuff
<CheckBox Content="CheckBox" HorizontalAlignment="Left" Height="23" Margin="29,0,0,44" Grid.Row="1" Style="{DynamicResource CheckBoxStyle1}" VerticalAlignment="Bottom" Width="125" Name="CheckBoxGutschrift" IsChecked="False" DataContext="{Binding}" Checked="CheckBoxGutschrift_Checked" Unchecked="CheckBoxGutschrift_Unchecked" ClickMode="Press" IsTabStop="False" />
Hope you understand my Problem! Thanks a lot for the answers, Ruediger
Upvotes: 0
Views: 2106
Reputation: 2433
You forgot to bind internal checkbox's IsChecked
property in the control template:
<CheckBox x:Name="checkBox" IsChecked="{TemplateBinding IsChecked}" ...
Upvotes: 1