5 Answers, 1 is accepted
0
Mitchell
Top achievements
Rank 1
answered on 08 Jan 2015, 12:26 AM
Using Decompile, I noticed that while RadCalendar has const values defined for max columns and rows, those const values are never used. Instead, the PropertyMetaData for the Columns property specifies a method to coerce the columns/rows to be between 1 and 4 (hardcoded). So, I was able to derive from RadCalendar, and call OverrideMetadata() to provide different metadata for the Columns property. I had to use reflection to make sure that the base class's OnColumnsChanged method was called. If put my derived class into the xaml of my simple example project (and make sure I have a style based on the style used for RadCalendar), I can specify 6 columns & get:
Yeah, it works! But, have I created the potential for some problems (aside from a possible upgrade issue from using reflection to call a private method)?
Thanks - Mitch
My little derived class is:
Yeah, it works! But, have I created the potential for some problems (aside from a possible upgrade issue from using reflection to call a private method)?
Thanks - Mitch
My little derived class is:
public
class
RadCalendarEx : RadCalendar
{
public
RadCalendarEx()
:
base
()
{
}
static
RadCalendarEx()
{
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(
typeof
(RadCalendar).TypeHandle);
RadCalendar.ColumnsProperty.OverrideMetadata(
typeof
(RadCalendarEx),
new
System.Windows.PropertyMetadata((
object
)1,
new
System.Windows.PropertyChangedCallback(RadCalendarEx.OnColumnsChangedEx),
new
CoerceValueCallback(RadCalendarEx.CoerceColumns)));
}
private
void
OnColumnsChangedEx()
{
//Call private handler in the RadCalendar class.
MethodInfo mi =
typeof
(RadCalendar).GetMethod(
"OnColumnsChanged"
, BindingFlags.NonPublic | BindingFlags.Instance);
if
(mi !=
null
)
{
mi.Invoke(
this
,
null
);
}
}
private
static
void
OnColumnsChangedEx(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
((RadCalendarEx)sender).OnColumnsChangedEx();
}
private
static
object
CoerceColumns(DependencyObject sender,
object
value)
{
//int num = Math.Min(4, (int)value);
//return Math.Max(1, num);
return
value;
}
}
0
Mitchell
Top achievements
Rank 1
answered on 08 Jan 2015, 12:29 AM
Hmm, my screenshot didn't get saved in my previous post. Trying again...
0
Mitchell
Top achievements
Rank 1
answered on 08 Jan 2015, 12:31 AM
Screenshot still not saving with my post. Attaching now instead...
0
Accepted
Hello Mitchell,
We have checked the provided code snippet and it seems that the approach you've used works fine. However, please notice that this is not a supported and there isn't any guarantee that it won't cause some unexpected behavior of RadCalendar.
Please, do not hesitate to contact us if you have any additional questions concerning Telerik controls.
Regards,
Nasko
Telerik
We have checked the provided code snippet and it seems that the approach you've used works fine. However, please notice that this is not a supported and there isn't any guarantee that it won't cause some unexpected behavior of RadCalendar.
Please, do not hesitate to contact us if you have any additional questions concerning Telerik controls.
Regards,
Nasko
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Mitchell
Top achievements
Rank 1
answered on 09 Jan 2015, 05:24 PM
Excellent. Yes, I understand and agree completely with the warning since the code is based on internal implementation details. But if there is no known big gotcha for why the number 4 was chosen, it is easier to weigh that risk vs getting more than 4 columns/rows. Thanks for the info!