Can the max column/row number be changed?

6 posts, 1 answers
  1. Mitchell
    Mitchell avatar
    45 posts
    Member since:
    Mar 2013

    Posted 07 Jan 2015 Link to this post

    At the current max of "4", I cannot create a strip of 6 or more months (for example). Is there a workaround for showing more than 4 columns/rows, or is there some technical issue in doing so?

    Thanks - Mitch
  2. Mitchell
    Mitchell avatar
    45 posts
    Member since:
    Mar 2013

    Posted 07 Jan 2015 Link to this post

    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:
    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;
            }
        }
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mitchell
    Mitchell avatar
    45 posts
    Member since:
    Mar 2013

    Posted 07 Jan 2015 in reply to Mitchell Link to this post

    Hmm, my screenshot didn't get saved in my previous post. Trying again...


  5. Mitchell
    Mitchell avatar
    45 posts
    Member since:
    Mar 2013

    Posted 07 Jan 2015 in reply to Mitchell Link to this post

    Screenshot still not saving with my post. Attaching now instead...
  6. Answer
    Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 09 Jan 2015 Link to this post

    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
     

    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.

     
  7. Mitchell
    Mitchell avatar
    45 posts
    Member since:
    Mar 2013

    Posted 09 Jan 2015 in reply to Nasko Link to this post

    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!
Back to Top
UI for WPF is Visual Studio 2017 Ready