I can't set the background of a RadWatermarkTextBox, I think it is a theme issue.

1 Answer 45 Views
Styling
Paul
Top achievements
Rank 2
Iron
Iron
Iron
Paul asked on 17 Feb 2024, 12:30 AM

https://www.telerik.com/forums/setting-background-color-when-control-is-readonly

The above link shows where someone had a similar issue but isn't clear on how to solve it.

I want to set a text box to not look disabled when it is readonly.
In the example below I set the background to red just to demonstrate that nothing happens.

I think it not happening because the application is using a theme (windows11)

Can I set the BasedOn to something that means "current theme", so that it will work?

<!-- Want readonly to not look disabled in many places -->

<Style x:Key="LxReadOnlyRadW"
       TargetType="telerik:RadWatermarkTextBox"
       BasedOn="{StaticResource {x:Type telerik:RadWatermarkTextBox}}">
    <Style.Triggers>
        <Trigger Property="IsReadOnly"
                 Value="True">
            <Setter Property="Background"
                    Value="red" />
        </Trigger>
    </Style.Triggers>
    <Setter Property="IsReadOnly"
            Value="True" />
    
</Style>


1 Answer, 1 is accepted

Sort by
1
Accepted
Dimitar
Telerik team
answered on 19 Feb 2024, 11:03 AM

Hi Paul,

You can set this in code with the following approach: 

  ThemeHelper.SetReadOnlyBackgroundBrush(textbox, Brushes.Green);

Let me know if I can be of further assistance.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Paul
Top achievements
Rank 2
Iron
Iron
Iron
commented on 19 Feb 2024, 12:57 PM

Does this mean that it can't be done via xaml?

I don't want to have to add a lot of code for every field that needs this.
Dimitar
Telerik team
commented on 20 Feb 2024, 07:53 AM

Hi Paul, 

It is possible to set it in a style like yours. Here is an example: 

<Style x:Key="LxReadOnlyRadW" TargetType="telerik:RadWatermarkTextBox">
    <Setter Property="helpers:ThemeHelper.ReadOnlyBackgroundBrush" Value="Blue"/>
    <Setter Property="IsReadOnly"  Value="True" />
    <Setter Property="helpers:ThemeHelper.ReadOnlyBrush" Value="Red"/>        
  
</Style>

Paul
Top achievements
Rank 2
Iron
Iron
Iron
commented on 20 Feb 2024, 10:52 AM

That's great. 
However, I can't find any equivalent to set the foreground colour, it still appears disabled. I thought it might be caused by the opacity property but that doesn't appear to be it.
Dimitar
Telerik team
commented on 20 Feb 2024, 01:08 PM

Hi Paul, 

It seems to work on my side, I have atached my test proejct. Am I missing something?

I am looking forward to your reply.

Paul
Top achievements
Rank 2
Iron
Iron
Iron
commented on 20 Feb 2024, 02:33 PM

<sys:Double x:Key="{x:Static telerik:Windows11ResourceKey.ReadOnlyOpacity}">1.0</sys:Double>

The above line that you send has made the difference. 
(I had tried to set Opacity but I should have been setting to ReadOnlyOpacity)
Dimitar
Telerik team
commented on 21 Feb 2024, 06:42 AM

Hi Paul, 

I am glad that this works. Do not hesitate to contact us if you have other questions.

Tags
Styling
Asked by
Paul
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or