In MVVM, how to scroll to the previously selected GanttTask

7 posts, 1 answers
  1. Jacky
    Jacky avatar
    6 posts
    Member since:
    Feb 2017

    Posted 21 Jun Link to this post

    In MVVM, how to scroll to the previously selected GanttTask when I update whole ObservableCollection gantt tasks?

    Thanks,

    -Jacky

     

  2. Dinko
    Admin
    Dinko avatar
    414 posts

    Posted 26 Jun Link to this post

    Hello Jacky,

    Thank you for contacting us.

    An approach which you can try is to create a SelectedTask property in your view model and bind it to the SelectedItem property of the RadGanttView. This property will preserve the item selected by the user. When you reset the collection you can use the ScrollView method for an example of the RadGanttView to scroll to a specific location. There is a Scrolling help article in our documentation which describes how you can set up RadGanttView so that the view is scrolled to a specified location.

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Jacky
    Jacky avatar
    6 posts
    Member since:
    Feb 2017

    Posted 26 Jun Link to this post

    Hi Dinko,

    Thank you for reply. but in an MVVM scenario, how can I call "ScrollView"  from my view model ?

    Thanks,

     

  4. Jacky
    Jacky avatar
    6 posts
    Member since:
    Feb 2017

    Posted 26 Jun in reply to Jacky Link to this post

    I  setup a SelectedTask (two way) in my view ,  I set back SelectedTask to previous task after I reset the collection. but the section didn't show up.
  5. Jacky
    Jacky avatar
    6 posts
    Member since:
    Feb 2017

    Posted 26 Jun Link to this post

    I tried to directly use control like below. but it didn't work.

    private void ResourceGantt_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    var gantt = sender as RadGanttView;
    var previousItems = e.RemovedItems;
    var newItems = e.AddedItems;
    if (newItems.Count == 0 && previousItems.Count > 0)
    {
    gantt.SelectedItem = previousItems[0];
    gantt.ScrollingService.ScrollIntoView(previousItems[0]);
    }
    }

  6. Jacky
    Jacky avatar
    6 posts
    Member since:
    Feb 2017

    Posted 28 Jun Link to this post

    if  previous Item is gantt's grandchild, it can't be set to select item?
  7. Answer
    Dinko
    Admin
    Dinko avatar
    414 posts

    Posted 29 Jun Link to this post

    Hi Jacky,

    Keep in mind that when you reset the collection new items will be created. You need to get the item from the new collection which correspondents to the previously selected item and set this item to the property bound to the SelectedItem of the RadGanttView. I have modified the project from my previous reply to demonstrates this approach. 

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top