Benjamin Ronneling
Benjamin Ronneling

Reputation: 821

How to have 100% opacity even when control is disabled in wpf C#

I have a textbox in my wpf, when I disable it the opacity decrease. This happens to tell the user that the textbox is not enable. Is there any way to disable a control and keep the look as the same?

Upvotes: 3

Views: 2009

Answers (2)

user10790294
user10790294

Reputation: 41

Use IsHitTestVisible="False" instead of IsEnabled="False"

Upvotes: 4

mm8
mm8

Reputation: 169200

Set the Template property to your own custom ControlTemplate:

<TextBox IsEnabled="False" Margin="10">
    <TextBox.Template>
        <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="#FF7EB4EA"/>
                </Trigger>
                <Trigger Property="IsKeyboardFocused" Value="true">
                    <Setter Property="BorderBrush" TargetName="border" Value="#FF569DE5"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </TextBox.Template>
</TextBox>

Upvotes: 3

Related Questions