This is a migrated thread and some comments may be shown as answers.

Override Background Colour with a Style

2 Answers 816 Views
WatermarkTextBox
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 15 Jul 2014, 12:27 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Masha
Telerik team
answered on 16 Jul 2014, 06:41 AM
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.
 
0
Raymond
Top achievements
Rank 1
answered on 15 Dec 2014, 01:02 AM
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
Tags
WatermarkTextBox
Asked by
Raymond
Top achievements
Rank 1
Answers by
Masha
Telerik team
Raymond
Top achievements
Rank 1
Share this question
or