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

visiblerangechanged command

4 Answers 103 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steven
Top achievements
Rank 1
Steven asked on 16 May 2012, 07:57 AM
Hello,

I'm handling the visiblerangechanged event via commanding as follows in my xaml:

<i:Interaction.Triggers>
 <i:EventTrigger EventName="VisibleRangeChanged" >
  <i:InvokeCommandAction Command="{Binding ViewDefinitionChangedCommand}" CommandParameter="{Binding ElementName=scheduleView, Path=ActiveViewDefinition}" />
 </i:EventTrigger>
</i:Interaction.Triggers>

In the VM, the ICommand is setup as follows:
ViewDefinitionChangedCommand = new DelegateCommand<ViewDefinitionBase>(OnViewDefinitionChanged);

The "OnViewDefinitionChanged" is getting executed when I change view, but when I change from say the Day view to the Week view the ViewDefinitionBase object getting passed to the execute method is the ViewDefinitionBase I am changing from, not the ViewDefinitionBase I am changing TO.

I also tried binding the ActiveViewDefinition to a VM property and handling the OnPropertyChanged event, but this doesnt seem to get fired (e.g. ActiveViewDefinition="{Binding Adf, Mode=TwoWay}" )

How do I handle the changing of the view definition such that I have access to the view being navigated to ?

Kind regards,

4 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 19 May 2012, 02:03 PM
Hi,

If only when changing from DayView to WeekView it gives you the DayView, that is because the WeekView inherits the DayView and you actually get the base class. In order to overcome this you have to use reflection and through the GetType() method to get the ViewDefinition reference's type.

Please let us know if that worked for you.

Kind regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Steven
Top achievements
Rank 1
answered on 21 May 2012, 03:24 AM
I understand the view definition heirarchy, but I actually get a WeekViewDefinition when navigating away from the week view and a DayViewDefinition when navigating away from the Day view.

The funny thing is, I also handle the VisibleRangeChanged event in the code-behind of the view, to do some GUI logic as shown below:

private void ScheduleViewVisibleRangeChanged(object sender, EventArgs e)
{
   if (scheduleView.ActiveViewDefinition.GetType() != typeof(MonthViewDefinition))
      Dispatcher.BeginInvoke(ScrollToFirstBooking);
}

This gets hit-up before the command delegate in the VM, and here at this point the scheduleView.ActiveViewDefinition is correct. Not sure why the command parameter is incorrect...

Basically the reason I've got the command delegate in the VM is because I'm going to be hitting up a WCF service to get a new set of appointments (depending on the view definition selected) as there a quite a few that are returned. The default view is "Day", but I'm providing access to both Week and Month views.  I dont want to get 7 (or 30) days worth of appointments by default as this would be quite a bit of data for views that will be rarely looked at...

I'm thinking of putting a ActiveViewDefinition property on the VM and handling its property changed. I would assign this VM property from the code-behind event handler. Obviously I would prefer if I could achive this via commanding alone, but it appears as though this may not be the case. Let me know if you can see and issues with what I propose, or if you can see where I might have been going wrong with the commading...

Thanks for answering.
0
Accepted
Konstantina
Telerik team
answered on 22 May 2012, 03:30 PM
Hi Steven,

Have you reviewed this online demo where is illustrated how to bind a command to the VisibleRange: http://demos.telerik.com/silverlight/#ScheduleView/LoadOnDemand? It might help you solve your issue, as without being acquainted with the whole of your scenario I cannot be sure what might be causing the problem.
However, binding to the ActiveViewDefinition property sounds also reasonable.

All the best,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Steven
Top achievements
Rank 1
answered on 23 May 2012, 02:41 AM
Thanks! all works
Tags
ScheduleView
Asked by
Steven
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Steven
Top achievements
Rank 1
Share this question
or