Willem
Willem

Reputation: 9476

Change WPF control's ControlTemplate to not be disabled

I have a Devexpress DateEdit and added a trigger for when IsEnabled=False to change the ControlTemplate to be a Label. This all works fine, but my problem is, that the Text of the Label is still Grayed out(Disabled).

My style:

<Style x:Key="DateTimeDropDownStyle" TargetType="{x:Type dxe:DateEdit}">
        <Setter Property="Mask" Value="dd MMM yyyy"/>
        <Setter Property="MaskUseAsDisplayFormat" Value="True"/>
        <Style.Triggers>
            <Trigger Property="dxe:DateEdit.IsEnabled" Value="False">
                <Setter Property="dxe:DateEdit.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Label Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, StringFormat={}{0:dd MMM yyyyy}}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

So, my question is, how do i change the Style so that the Label is not disabled?

Upvotes: 0

Views: 1545

Answers (1)

XAMeLi
XAMeLi

Reputation: 6289

Try setting Foreground on the Label in your template.

If it doesn't help, you'd have to edit the control template for the label. A basic one is:

<ControlTemplate TargetType="{x:Type Label}">
    <Border Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}">
        <ContentPresenter Margin="{TemplateBinding Padding}"/>    
    </Border>
    <ControlTemplate.Triggers>
        <!--This is the trigger to remove-->
        <Trigger Property="IsEnabled"
                 Value="False">
            <Setter Property="Foreground"
                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

Upvotes: 2

Related Questions