I have a panel class ExRadPanel, that inherits from RadPanel. I try to apply to it a copy of the style that is used for PropertyGridHelpElement in RadPropertyGrid. Below is my test code, but it doesn't work properly. Some style is attached to FillPrimitive inside ExRadPanel, but the visual effect is not like I expect.
Is that possible to make modify a theme in runtime to make a copy of the required style setting with proper settings?
Is that possible to make modify a theme in runtime to make a copy of the required style setting with proper settings?
private static void FixTheme(Theme theme)
{
// try to add registration
var sg = theme.FindStyleGroup(typeof(RadPropertyGrid).FullName);
sg.Registrations.Add(new MyStyleRegistration
{
RegistrationType = "ElementTypeControlType",
ElementType = "Telerik.WinControls.RootRadElement",
ControlType = typeof(ExRadPanel).FullName
});
sg.Registrations.Add(new MyStyleRegistration
{
RegistrationType = "ElementTypeControlType",
ElementType = typeof(RadPanelElement).FullName,
ControlType = typeof(ExRadPanel).FullName
});
var copy = sg.PropertySettingGroups.ToArray();
foreach (var settingGroup in copy)
{
if (settingGroup.Selector is null)
continue;
if (settingGroup.Selector.Value != nameof(PropertyGridHelpElement))
continue;
{
// trying this ...
var newSg = new PropertySettingGroup
{
Selector = new ElementSelector(settingGroup.Selector.Type, nameof(RadPanelElement)),
BasedOn = settingGroup.BasedOn
};
newSg.Repositories.AddRange(settingGroup.Repositories);
newSg.PropertySettings.AddRange(settingGroup.PropertySettings);
sg.PropertySettingGroups.Add(newSg);
}
{
// ... and this
var newIi = new PropertySettingGroup
{
Selector = new ElementSelector(ElementSelectorTypes.TypeSelector, typeof(FillPrimitive).FullName),
BasedOn = settingGroup.BasedOn
};
newIi.Repositories.AddRange(settingGroup.Repositories);
newIi.PropertySettings.AddRange(settingGroup.PropertySettings);
sg.PropertySettingGroups.Add(newIi);
}
}
}