Disabled controls are too light

11 posts, 1 answers
  1. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 01 Feb 2013 Link to this post

    I'm getting complaints from the users that disabled controls on our data forms are too hard to read.

    Is there some simple, global method for over-riding the foreground color selection used?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Feb 2013 Link to this post

    Hello Jeffrey,

    You can try editing the template of the data form and change the background of the border named "Background_Disabled". Let me know in case this does not lead you to the desired result.

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 04 Feb 2013 Link to this post

    Actually, we're already doing that. When we load the form, we set the background of every form with the name "Background_Disabled" to Brushes.Transparent.

    The problem is that the foreground colors are too light.


  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 05 Feb 2013 Link to this post

    Hello Jeffrey,

    The only thing we do when RadDataForm is disabled is to place a Border with different background once IsEnabled property is changed to "false". So, changing it should do the trick. Will it be possible to clarify which theme you are working with ?  

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 05 Feb 2013 Link to this post

    The controls that are being displayed in the form are drawing with a lighter foreground color when the form is disabled than when it is not. This may be something that is happening within the individual controls, rather than in the form itself, but it's clearly happening.

    "Will it be possible to clarify which theme you are working with ?"

    All of them.  Or rather, our application allows the user to select which theme to use.

    But all of the provided themes show this problem.
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Feb 2013 Link to this post

    Hi Jeffrey,

    The theme with the lightest elements in disabled state is most probably Windows8Theme. I have tested the case and if the Background in disabled state is set to Transparent, all elements of the DataForm look ok. Still, all editing controls are in disabled state as well. Do you refer to them when saying the data form is not readable ? If that is the case, you will need to change their disabled states as well.  

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 06 Feb 2013 Link to this post

    Yes, I am referring to the controls in the DataForm. If the form is disabled, then all of the controls are disabled, and the foreground color for each of the controls is too light.  Regardless of which theme is used.

    Currently, I'm setting the Background_Disabled border to transparent with:
    void myForm_Loaded(object sender, RoutedEventArgs e)
    {
        foreach (Border border in this.ChildrenOfType<Border>())
        {
            if (border.Name == "Background_Disabled")
                border.Background = Brushes.Transparent;
        }
    }
    But I've been unable make this work in setting the foreground colors of the controls on the form.

    This, for example:
    foreach (FrameworkElement element in this.ChildrenOfType<FrameworkElement>())
    {
        PropertyInfo foregroundProperty = element.GetType().GetProperty("Foreground");
        if (foregroundProperty != null)
            foregroundProperty.SetValue(element, Brushes.Red, null);
    }
    will successfully set the foreground color of every control on my form to red, when the form is opened in edit mode, but when the form is disabled, the labels stay red, but the foreground colors of all of the regular controls (textboxes, checkboxes, dropdowns, etc.) turn light gray.

  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Feb 2013 Link to this post

    Hi Jeffrey,

    I tested the case, but I was not able to reproduce the behavior where the editors do not get the Red foreground. I am attaching the project I used for the test. Is there something that I am missing ?  

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 07 Feb 2013 Link to this post

    I can see the foreground colors changing, in your example, as I wished they would in my code.

    Two complexities in my code that I hadn't thought were relevant, but which seem to be:

    1. The fields in my forms have explicit content set, rather than the one that they would generate themselves by default.
    2. Rather than auto-generating the fields, the forms have templates set - and - those templates are from an external source, and are not part of the application.

    In my app, the form templates are loaded from external files, and are constructed using XamlReader.Load(). But it doesn't look like it's the external loading that is the problem.

    Starting with your example:

    First: I created a DataTemplate that defined three DataFormDataFields, in Windows.Resources.
    And I bound the form's ReadOnlyTemplate to that DataTemplate.
    And the foreground colors changed as desired.

    Second: I modified one the Name field in the template to use an explicit TextBox, instead of the auto-generated control.
    And the foreground colors still changed as desired. Even in the explicit TextBox.

    Third: I removed the form's ReadOnlyTemplate binding, and set ReadOnlyTemplate in MainWindow_Loaded()
    And then, finally, I did not see the foreground color change, in the explicit TextBox.

    The attachment mechanism in this forum will not allow .zip files, so I created a support ticket: 657307 to which I've attached a zip file containing this third example.


  11. Answer
    Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 08 Feb 2013 Link to this post

    Hello Jeff,

    Thank you for the project.

    In your case, when the Foreground property is set the content of DataFormDataField is still not changed. Following code will resolve the problem:

    private void officeBlackDataForm_Loaded(object sender, RoutedEventArgs e)
        {
          foreach (Border border in this.ChildrenOfType<Border>())
          {
            if (border.Name == "Background_Disabled")
              border.Background = Brushes.Transparent;
          }
       
          Dispatcher.BeginInvoke(new Action(() =>
          {
            foreach (FrameworkElement element in this.ChildrenOfType<FrameworkElement>())
            {
              PropertyInfo foregroundProperty = element.GetType().GetProperty("Foreground");
              if (foregroundProperty != null)
                foregroundProperty.SetValue(element, Brushes.Red, null);
            }
          }));
            
        }

     

    Greetings,
    Yordanka
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 08 Feb 2013 Link to this post

    So, setting the foreground color works, it's just that I've been doing it too early.

    Thanks for your help.
Back to Top
UI for WPF is Visual Studio 2017 Ready