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
9 Answers, 1 is accepted
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.
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;
}
}
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.
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.
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;
}
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.
Indeed, the proper way to go is to create style for RadComboBox instead. Do you have any troubles with the implementation ?
Maya
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.