WPF 获取默认 TextBox 鼠标悬停颜色

WPF get the default TextBox mouse over color

我想用与默认 TextBox 鼠标悬停颜色(最好是主题感知)完全相同的颜色为控件着色。例如

<Rectangle Fill={x:Static WhatDoIPutHere}/>

我可以在哪个key/resource下访问颜色?在我当前的系统中,它似乎是 #ff7eb4ea 淡蓝色,但 *Highlight*、*Control* 或 *Border* System Colors 的 none 似乎具有该值。

你说得对! MouseOver Border 颜色为#FF7EB4EA;在 TextBox.MouseOver.Border 键下。我认为您无法从外部访问这些 Resources。您可以从 TextBox 的默认 ControlTemplate 中获取这些详细信息。这是

<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
<ControlTemplate TargetType="{x:Type TextBox}">
    <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
        <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Opacity" TargetName="border" Value="0.56"/>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
        </Trigger>
        <Trigger Property="IsKeyboardFocused" Value="true">
            <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

如果您使用 Blend for Visual Studio,请参考 this to know how to access default Templates of any control. If you're using Visual Studio, you can check this