Override Background Colour with a Style

3 posts, 1 answers
  1. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 14 Jul 2014 Link to this post

    I am attempting to set a style for the RadWatermarkTextbox as follows;

    <Style TargetType="telerik:RadWatermarkTextBox" x:Key="RadWatermark">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsActive}" Value="False">
                <Setter Property="TextBlock.Foreground" Value="Red"/>
                <Setter Property="TextBlock.Background" Value="LightYellow" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    The foreground colour changers to red but the background appears grey.  I haver tried various opacity settings and also;

    <Style TargetType="telerik:RadWatermarkTextBox" x:Key="RadWatermark">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsActive}" Value="False">
                <Setter Property="TextBlock.Foreground" Value="Red"/>
                <Setter Property="TextBlock.Background" Value="LightYellow" />
                <Setter Property="Background" Value="LightYellow" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    but the best I seem to get is a dirty-yellow background.

    How do I override the default "battleship grey"?
  2. Answer
    Masha
    Admin
    Masha avatar
    355 posts

    Posted 16 Jul 2014 Link to this post

    Hi Raymond,

    The issue occurs because inside the ControlTemplate of RadWatermarkTextBox there is Opacity=0.6 set and Gray background through VisualStates when the control is disabled.  In order to have the correct background color you should override the ControlTemplate as follow:

    <DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}}" Value="False">
        <Setter Property="TextBlock.Foreground" Value="Red"/>
     
        <Setter Property="Background" Value="LightYellow" />
        <Setter Property="Template">
     
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
                    CornerRadius="1" Opacity="1"/>
                        <ScrollViewer x:Name="PART_ContentHost"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    BorderThickness="0"
                    IsTabStop="False"
                    Cursor="Arrow"
                    Padding="{TemplateBinding Padding}"
                    Margin="{TemplateBinding BorderThickness}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </DataTrigger>

    This way everything should work as expected.

    I hope this would be helpful.

    Regards,
    Masha
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 14 Dec 2014 in reply to Masha Link to this post

    Hi Masha,

    Sorry to take so long to reply - I was dragged away on another project.

    This fixed my problem - thanks very much.

    Regards,

    Ray
Back to Top