In my application I want that a CheckBox
if it get's the Keyboardfocus should not have a dotted border. Therfor I have set the FocusVisualStyle
to null. The definition of the CheckBox
looks like:
<CheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,5,0,10" Style="{StaticResource MyCheckBoxStyle}"
IsChecked="{Binding UseOriginalPath, UpdateSourceTrigger=PropertyChanged}" FocusVisualStyle="{x:Null}" >
<TextBlock TextWrapping="Wrap" Text="Use the original path"/>
</CheckBox>
My custom style for the CheckBox
looks like:
<Style TargetType="CheckBox" x:Key="MyCheckBoxStyle">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid Margin="2.5">
<Border BorderThickness="0" BorderBrush="Green" Margin="-25,-2.5,-6,-2.5" x:Name="border"/>
<ContentPresenter Content="{TemplateBinding Content}"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=CheckBox}, Path=IsFocused}" Value="True">
<Setter TargetName="border" Property="BorderThickness" Value="1.5"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Until here everything just works as expected. If I focus the CheckBox
with the Tab-Key there is no dotted border around it.
But if I remove the FocusVisualStyle="{x:Null}"
from the CheckBox
definition and want to move it to the syle it wont work.
So the definition of the CheckBox
now looks like:
<CheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,5,0,10" Style="{StaticResource MyCheckBoxStyle}"
IsChecked="{Binding UseOriginalPath, UpdateSourceTrigger=PropertyChanged}">
<TextBlock TextWrapping="Wrap" Text="Use the original path"/>
</CheckBox>
And the Style looks like:
<Style TargetType="CheckBox" x:Key="MyCheckBoxStyle">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid Margin="2.5">
<Border BorderThickness="0" BorderBrush="#79B100" Margin="-25,-2.5,-6,-2.5" x:Name="border"/>
<ContentPresenter Content="{TemplateBinding Content}"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=CheckBox}, Path=IsFocused}" Value="True">
<Setter TargetName="border" Property="BorderThickness" Value="1.5"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
Now if I focus the CheckBox
with the Tab-Key there are the dottet borders. I don't understand what I'm doing wrong here?
Aucun commentaire:
Enregistrer un commentaire