visiblerangechanged command

5 posts, 1 answers
  1. Steven
    Steven avatar
    10 posts
    Member since:
    Apr 2011

    Posted 16 May 2012 Link to this post

    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,
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 19 May 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Steven
    Steven avatar
    10 posts
    Member since:
    Apr 2011

    Posted 20 May 2012 Link to this post

    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.
  5. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 22 May 2012 Link to this post

    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 >>
  6. Steven
    Steven avatar
    10 posts
    Member since:
    Apr 2011

    Posted 22 May 2012 Link to this post

    Thanks! all works
Back to Top
DevCraft banner