Does the reusable way to put a bright red frame around any item currently have focus?

I have several windows with mostly lists, text fields and check boxes. When you click on one to get focus, I need a way to make them outlined in a colorful box (boss orders). Is there a way to make this easier than overriding the default style for all of these controls? I have never done this before, so it would take a lot of effort on my part to understand this.

+1
source share
1 answer

You can try adding FocusVisualStyle to controls that need different focus rectangle styles.

Top link

, FocusVisualStyle; " " , , , , .

- Window Xaml

<Window.Resources>
    <Style x:Key="NewFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border>
                        <Rectangle Stroke="Red"  Margin="2" StrokeThickness="1"  StrokeDashArray="1 2" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

Application.Xaml.

<Application.Resources>
    <Style x:Key="NewFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border>
                        <Rectangle Stroke="Red"  Margin="2" StrokeThickness="1"  StrokeDashArray="1 2" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>

:

<ComboBox FocusVisualStyle="{StaticResource NewFocusVisual}"  Height="23" HorizontalAlignment="Left" Margin="238,102,0,0" Name="ComboBox1" VerticalAlignment="Top" Width="120" />
<CheckBox FocusVisualStyle="{StaticResource NewFocusVisual}" Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="238,71,0,0" Name="CheckBox2" VerticalAlignment="Top" />
<TextBox FocusVisualStyle="{StaticResource NewFocusVisual}" Height="23" HorizontalAlignment="Left" Margin="238,144,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" />

, Focus , Microsoft , :

Microsoft: . , . , , , , , IsFocused IsFocusWithin.


, TextBox,

<Application.Resources>
    <Style TargetType="TextBox" >
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Control.BorderBrush" Value="Red"  />
                <Setter Property="Control.BorderThickness" Value="3" />
            </Trigger>
        </Style.Triggers>
    </Style>

</Application.Resources>
+5

All Articles