Reputation: 83
In WPF I would like the label in the CheckBox to behave like a button, so when I toggle the checkbox to ON, I would like the label to change to a button, and when I toggle the checkbox to OFF, then button go change back to label.
Here is what I have so far
<CheckBox Margin="2,0,2,0"
IsChecked="{Binding IsSteps}"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Height="32"
FocusVisualStyle="{x:Null}"
Style="{StaticResource SliderCheckBoxStyle}">
<CheckBox.Content>
<TextBlock Text="Steps" Foreground="#FFFFFFFF" FontFamily="Lucida Sans" FontSize="8" FontWeight="Bold"/>
</CheckBox.Content>
</CheckBox>
Upvotes: 0
Views: 961
Reputation: 275
In your Checkbox.Content, create a StackPanel with both TextBlock and Button. Then, You can bind your TextBlock.Visibilty and Button.Visibilty to "IsSteps" with triggers and setters.
<CheckBox Margin="2,0,2,0"
IsChecked="{Binding IsSteps}"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Height="32"
FocusVisualStyle="{x:Null}"
Style="{StaticResource SliderCheckBoxStyle}">
<CheckBox.Content>
<StackPanel>
<TextBlock Text="Steps" Foreground="#FFFFFFFF" FontFamily="Lucida Sans" FontSize="8" FontWeight="Bold">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSteps}" Value="True">
<Setter Property="Visibility" Value="Collapsed">
</DataTrigger>
</Style.Triggers>
</Style>
<TextBlock.Style>
</TextBlock>
<Button>
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSteps}" Value="False">
<Setter Property="Visibility" Value="Collapsed">
</DataTrigger>
</Style.Triggers>
</Style>
<Button.Style>
</Button>
</StackPanel>
</CheckBox.Content>
</CheckBox>
Now their Visibility property depends on IsSteps from your DataContext object, so when one appears and other one disappears.
Upvotes: 2