0

IsEnabled = falseの場合のWPFテキストボックスでは、背景色は灰色ですが、この背景色はどこにも設定されていません。設定すると

  <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Background" Value="Blue"/>

プロパティでIsEnabled="true"を変更すると、背景色が変更される可能性があります。誰かがIsEnabled="False"でバックグラウンドプロパティが機能しない理由を説明できますか

4

1 に答える 1

1

実際、TextBoxテンプレート内にあるBorderの背景を更新する必要があります。したがって、トリガーセクションで、テキストボックスのテンプレートを上書きし、そこに適切な背景を設定できます。

ここにあるすべてのデフォルトのTextBoxテンプレート。

<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBoxBase}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="MinWidth" Value="120"/>
    <Setter Property="MinHeight" Value="20"/>
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                <Border 
        Name="Border"
        CornerRadius="2" 
        Padding="2"
        Background="{StaticResource WindowBackgroundBrush}"
        BorderBrush="{StaticResource SolidBorderBrush}"
        BorderThickness="1" >
                    <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="Border" Property="Background" Value="Blue"/>
                        <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBackgroundBrush}"/>
                        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2012-06-22T12:17:38.827 に答える