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

Setting background color when control is readonly

6 Answers 289 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 1
Veteran
Hans asked on 19 Feb 2019, 09:22 AM

Hi,

How can I set the background color (in XAML) of a NumericUpDown control when IsReadOnly is set to true ?  I tried using a style but without succes ...

Regards,
Hans

6 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 21 Feb 2019, 02:24 PM
Hi Hans,

I've prepared a small sample project where defining the following style correctly updates the background of the RadNumericUpDown when it is in the read-only state:

<Style BasedOn="{StaticResource RadNumericUpDownStyle}" TargetType="telerik:RadNumericUpDown">
    <Style.Triggers>
        <Trigger Property="IsReadOnly" Value="True">
            <Setter Property="Background" Value="LightGray" />
        </Trigger>
    </Style.Triggers>
</Style>

Please note that if you're using the StyleManager approach for styling the controls with the Xaml assemblies, you should omit the BasedOn attribute of the style.

Could you please also test this at your end and let me know if such an approach would work for you? I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hans
Top achievements
Rank 1
Veteran
answered on 25 Feb 2019, 11:27 AM

Hi Dilyan,

Thank you for your reply.  I don't know why, but the style is not applied at runtime. Here's my control:

<telerik:RadNumericUpDown Grid.Row="10" Grid.Column="1" Value="{Binding SelectedCustomerCreditControl.TotalOutstandingAmount, Mode=OneWay}" IsReadOnly="True" ShowButtons="False" ValueFormat="Numeric" NumberDecimalDigits="2" NumberDecimalSeparator="." >
    <telerik:RadNumericUpDown.Style>
        <Style TargetType="{x:Type telerik:RadNumericUpDown}">
            <Style.Triggers>
                <Trigger Property="IsReadOnly" Value="True">
                    <Setter Property="Background" Value="DodgerBlue" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </telerik:RadNumericUpDown.Style>
</telerik:RadNumericUpDown>

In desing mode the control has the right color, but at run time, it seems like the style is overwritten and the control has the default background color.

Applying the same style to a simple TextBox works fine, so the problem is realy related to the RadNumericUpDown control.

Any ideas ?

Regards,
Hans

 

 

 

0
Dinko
Telerik team
answered on 28 Feb 2019, 09:28 AM
Hi Hans,

My name is Dinko and I'm stepping in for my colleague Dilyan, who is currently out of the office.

I have double checked the example provided by my colleague Dilyan and it is working as expected on my side. The style is applied runtime and design time. It is strange that the Style is not applied on your side. May I ask you some more details about your project set up.
  • What version of our controls are you using? 
  • Can you run the project provided by Dilyan and let me know without doing any modifications if the style is applied correctly?
  • I am assuming that the provided code snippet is from your application. Can you double check if they are other styles which target the RadNumericUpDown control?
  • Can you try to isolate this behavior is a stand-alone project?

I am looking forward to your reply.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hans
Top achievements
Rank 1
Veteran
answered on 05 Mar 2019, 07:59 AM

Hello Dinko,

the problem is due to the Office2016 theme that is set in the App.xaml.cs

Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Office2016Theme();

When I put this line in comment, the style is applied. 

Obiously, I would like to keep the Office2016 style AND have the ReadOnly style applied to my RadNumericUpDown control.

Regards,
Hans

 

 

 

0
Hans
Top achievements
Rank 1
Veteran
answered on 05 Mar 2019, 09:59 AM

Hi,

I solved the problem by using implicit styles instead of the StyleManager.

Regards,
Hans

0
Dinko
Telerik team
answered on 07 Mar 2019, 10:59 AM
Hi Hans,

I am happy to hear that you found a solution for your case. If you have any other questions you can open a new thread with your questions inside.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
NumericUpDown
Asked by
Hans
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
Hans
Top achievements
Rank 1
Veteran
Dinko
Telerik team
Share this question
or