Editing template of RadComboBox inside RadPropertyGrid

10 posts, 0 answers
  1. Michael
    Michael avatar
    6 posts
    Member since:
    Feb 2013

    Posted 11 Mar 2013 Link to this post

    Hi,

    I have a control template that needs to be applied to all of my combo boxes in my project, including those in the property grid I have. I am using the Editable and and noneditable template to get the style that I am looking for. My property grid uses items such as textboxes, checkboxes, datetimepickers, and comboboxes. Is there a way to apply the same control template to all combo boxes that appear in my propertygrid?

    Thanks
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 12 Mar 2013 Link to this post

    Hello,

    May I ask you, which version of RadControls you are currently using? With Q1 2013 we have added a DataFieldLoaded event, so that you can subscribe to it and set the respective style to the desired ComboBox instance, which is the field's Content.

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    6 posts
    Member since:
    Feb 2013

    Posted 12 Mar 2013 Link to this post

    Hi

    Thanks for the response. I am using 2013 Q1, but I could only find FieldLoaded. It still worked fine. 
    private void RadPropertyGrid_FieldLoaded(object sender, Telerik.Windows.Controls.Data.PropertyGrid.FieldEventArgs e)
            {
                if (e.Field.Content is Telerik.Windows.Controls.RadComboBox)
                {
                    Telerik.Windows.Controls.RadComboBox cb = e.Field.Content as Telerik.Windows.Controls.RadComboBox;
                    cb.SetResourceReference(Telerik.Windows.Controls.RadComboBox.NonEditableTemplateProperty, "NonEditableTemplate");
                    cb.SetResourceReference(Telerik.Windows.Controls.RadComboBox.EditableTemplateProperty, "EditableTemplate");
                    SolidColorBrush blue = new SolidColorBrush();
                    blue.Color = Color.FromArgb(255,58,85,101);
                    cb.Foreground = blue;
                }
                if (e.Field.Content is Telerik.Windows.Controls.RadDateTimePicker)
                {
                    Telerik.Windows.Controls.RadDateTimePicker dtp = e.Field.Content as Telerik.Windows.Controls.RadDateTimePicker;
                    SolidColorBrush blue = new SolidColorBrush();
                    blue.Color = Color.FromArgb(255, 58, 85, 101);
                    dtp.Foreground = blue;
                }
            }
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 12 Mar 2013 Link to this post

    Hi,

    Yes, it is actually FieldLoaded. Sorry, it seems that I have not learned the changes in the API by heart yet :)

    Regards,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 11 Apr 2013 Link to this post

    Can you please show an example of the use of this DataFieldLoaded event? I want to change the style of the comboboxes/textboxes of my auto-generated property grid items!
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Apr 2013 Link to this post

    Hi Kristoffer,

    In order to update a property of an editor of the field, you can try something like:

    private void RadPropertyGrid_FieldLoaded(object sender, Telerik.Windows.Controls.Data.PropertyGrid.FieldEventArgs e)
            {
                var textBox = e.Field.Content as TextBox;
                if (textBox != null)
                {
                    textBox.FontSize = 20;
                }
            }
     

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 03 Jun 2013 Link to this post

    Thanks Maya! That did the trick :)

    But... what if I want comboboxes to be transparent? This won't work:
    if (e.Field.Content is RadComboBox)
    {
        var comboBox = e.Field.Content as RadComboBox;
        comboBox.Background = null;
    }

  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Jun 2013 Link to this post

    Hi Kristoffer,

    You can set the background to be transparent:

    private void propertyGrid_FieldLoaded(object sender, FieldEventArgs e)
            {
                var comboBox = e.Field.Content as RadComboBox;
                if (comboBox != null)
                {
                    comboBox.Background = new SolidColorBrush(Colors.Transparent);
                }
            }

    But since there are elements underneath, you might not get the color you want. What is the behavior that you want to achieve ?  

    Regards,
    Maya
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 03 Jun 2013 Link to this post

    I'm simply trying to style the comboboxes of the property grid. Setting the background to transparent doesn't help as it is already transparent (I looked at your templates). However, by duplicating your templates and modifying it, I managed to create what I want; a transparent combobox.
  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Jun 2013 Link to this post

    Hi Kristoffer,

    Indeed, the proper way to go is to create style for RadComboBox instead. Do you have any troubles with the implementation ?  

    Regards,
    Maya
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready