Setting background color when control is readonly

7 posts, 0 answers
  1. Hans
    Hans avatar
    30 posts
    Member since:
    Nov 2017

    Posted 19 Feb Link to this post

    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

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    908 posts

    Posted 21 Feb Link to this post

    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.
  3. Hans
    Hans avatar
    30 posts
    Member since:
    Nov 2017

    Posted 25 Feb in reply to Dilyan Traykov Link to this post

    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

     

     

     

  4. Dinko
    Admin
    Dinko avatar
    874 posts

    Posted 28 Feb Link to this post

    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.
  5. Hans
    Hans avatar
    30 posts
    Member since:
    Nov 2017

    Posted 05 Mar Link to this post

    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

     

     

     

  6. Hans
    Hans avatar
    30 posts
    Member since:
    Nov 2017

    Posted 05 Mar in reply to Hans Link to this post

    Hi,

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

    Regards,
    Hans

  7. Dinko
    Admin
    Dinko avatar
    874 posts

    Posted 07 Mar Link to this post

    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.
Back to Top