I have a RadComboBox from telerik which has some protected setters for a few of it's properties. I want to be able to set each and every property so I derived from that control and I have created a custom control. I also did the same thing for it's items component.
public class RadComboBoxItem : ListBoxItem
{
...
public bool IsHighlighted
{
get
{
return (bool)GetValue(IsHighlightedProperty);
}
protected set
{
this.SetValue(IsHighlightedPropertyKey, value);
}
}
...
}
public class MyCustomComboBoxItem : RadComboBoxItem
{
public void HighlightItem(bool _default)
{
this.IsHighlighted = _default;
}
}
In my case I have a list of RadComboBoxItems and I want to create a new list of type MyCustomComboBoxItem, so I can access the setter for each item from the first list based on the data:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
...
foreach (RadComboBoxItem _item in _listOfRadComboBoxItems)
{
MyCustomComboBoxItem _customCBI = new MyCustomComboBoxItem();
_customCBI.Load(_customCBI.GetType(), _item, true);
_listOfCustomCBI.Add(_newB2);
}
}
}
I found another post with an explanation on what I am trying to do but my case is a little different and I borrowed the Load method from here:
Updating ObservableCollection Item properties using INotifyPropertyChanged
public static class ExtentionMethods
{
public static void Load<T>(this T target, Type type, T source, bool deep)
{
foreach (PropertyInfo property in type.GetProperties())
{
if (property.CanWrite && property.CanRead)
{
if (!deep || property.PropertyType.IsPrimitive || property.PropertyType == typeof(String))
{
property.SetValue(target, property.GetValue(source, null), null);
}
else
{
object targetPropertyReference = property.GetValue(target, null);
targetPropertyReference.Load(targetPropertyReference.GetType(), property.GetValue(source, null), deep);
}
}
}
}
}
Recap: What I am trying to do here is create a custom ComboBox from Telerik's RadComboBox. This has ComboBoxItems that have the IsHighlighted dependency property setter protected. I created MyCustomComboBoxItem to circumvent this limitation but I can't get to copy the RadComboBoxItem into MyCustomComboBoxItem.
Reason: I want to be able to set it, so I can help the user in a better experience.
Thanks.