This is a migrated thread and some comments may be shown as answers.

Setting ActiveViewDefinition TickLengths?

3 Answers 170 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 29 Sep 2011, 10:11 PM
Hi All,

Can someone tell me how to set properties such as Major/MinorTickLength in code (C#)? In the Telerik ExamplesCS_SL.ScheduleViewConfigurator.Silverlight.Example.xaml file, the binding is

SelectedItem="{Binding ActiveViewDefinition.MinorTickLength, ElementName=ScheduleView, Mode=TwoWay}"


However, in code I don't see MinorTickLength as a property of ActiveViewDefinition. I'm trying to do something like this:

        public void ApplySettings(RadScheduleView scheduleView)<br>
        {
          
if (scheduleView.ActiveViewDefinition == null)
               
return;
           
if (DaysToShow.HasValue)
                scheduleView.ActiveViewDefinition.VisibleDays = DaysToShow.GetValueOrDefault(scheduleView.ActiveViewDefinition.VisibleDays);
           
if (MinorTicks != null)
//                scheduleView.ActiveViewDefinition.MinorTickLength = MinorTicks;
// NO MinorTickLength property!
//
            if (MajorTicks != null)
                scheduleView.ActiveViewDefinition.MajorTickLength = MajorTicks;
            if (MinTimeRulerExtent.HasValue)
                scheduleView.ActiveViewDefinition.MinTimeRulerExtent = MinTimeRulerExtent.GetValueOrDefault(scheduleView.ActiveViewDefinition.MinTimeRulerExtent);
        }

EDIT:
I think I've solved it like this:

            MultidayViewDefinition multidayView = scheduleView.ActiveViewDefinition as MultidayViewDefinition;
                
if (multidayView != null)
            {
               
if (MinorTicks != null)
                    multidayView.MinorTickLength = MinorTicks;
               
if (MajorTicks != null)
                    multidayView.MajorTickLength = MajorTicks;
            }


Is that the proper way to do it?

3 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 30 Sep 2011, 09:45 AM
Hello Scott,

That's the best way to do it.

The ActiveViewDefinition is of a type that is base class for the DayViewDefinition and WeekViewDefinition for example. It does not have the tick length properties but it is fine to cast it and set the lengths. The null check you've done should handle the fact that month view for example does not have such properties.

All the best,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Scott
Top achievements
Rank 1
answered on 03 Oct 2011, 02:47 AM
Hi Pana,

Thanks for the reply. That code is working for me, but I do have one additional question. In the code below, I'm trying to read the current values from the ActiveViewDefinition whenever the user changes views. I want to use these values to set the .SelectedItem properties of comboBoxes which display a list of all possible tick lengths, etc.

My issue is the multiDayView.MajorTickLength and multiDayView.MinorTickLength properties seem to be null whenver I read them after a view change. Am I doing this properly?

How can I query the "current" major/minor tick length values from ActiveViewDefinition?

My RadScheduleView.ActiveViewDefinition is bound to the following:

private ViewDefinitionBase _activeViewDefinition;
public ViewDefinitionBase ActiveViewDefinition
{
    get
    {
        return _activeViewDefinition;
    }
    set
    {
        if (value != _activeViewDefinition)
        {
            _activeViewDefinition = value;
            OnPropertyChanged("ActiveViewDefinition");
            PublishDisplaySettings(_activeViewDefinition);
        }
    }
}


Code to publish the ActiveViewDefinition's current settings to the rest of the application:

private void PublishDisplaySettings(ViewDefinitionBase viewDefinition)
{
    if (viewDefinition == null)
        return;
 
    try
    {
        ScheduleDisplaySettingsChangeEventArgs args = new ScheduleDisplaySettingsChangeEventArgs();
        args.DaysToShow =  viewDefinition.VisibleDays;
        args.MinTimeRulerExtent = viewDefinition.MinTimeRulerExtent;
 
        MultidayViewDefinition multidayView = viewDefinition as MultidayViewDefinition;
        if (multidayView != null)
        {
            // Major/minor tick length properties seem to be always null
            args.MajorTicks = multidayView.MajorTickLength as ITickLengthProvider;
            args.MinorTicks = multidayView.MinorTickLength as ITickLengthProvider;
            args.ViewOrientation = multidayView.Orientation;
        }
        else
        {
            // Use Defaults
            args.ViewOrientation = Orientation.Horizontal;
            args.MajorTicks = args.MinorTicks = new AutomaticTickLengthProvider();
 
        }
        ApplicationGlobalService.Container.Resolve<IEventAggregator>()
            .GetEvent<ReportScheduleDisplaySettingsEvent>()
            .Publish(args);
    }
    catch (Exception e)
    {
        Console.WriteLine("PublishDisplaySettings exception: {0}", e.Message);
    }
}

Cheers,
Scott
0
Pana
Telerik team
answered on 07 Oct 2011, 06:58 AM
Hi Scott,

The default value of these properties is indeed null. In that case they fallback to internal automatic tick length provider. I would guess you need to create a dictionary of sort that would keep the default tick length providers for the different views and use it when the ActiveViewDefinition changes to pick a selected item in the RadComboBox.

I am sorry for the inconvenience. As easy and intuitive your approach may look you will need to do some extra work to make it through.

Kind regards,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
ScheduleView
Asked by
Scott
Top achievements
Rank 1
Answers by
Pana
Telerik team
Scott
Top achievements
Rank 1
Share this question
or