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

In MVVM, how to scroll to the previously selected GanttTask

6 Answers 137 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Jacky
Top achievements
Rank 1
Jacky asked on 21 Jun 2017, 09:13 PM

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

Thanks,

-Jacky

 

6 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 26 Jun 2017, 12:57 PM
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Jacky
Top achievements
Rank 1
answered on 26 Jun 2017, 06:00 PM

Hi Dinko,

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

Thanks,

 

0
Jacky
Top achievements
Rank 1
answered on 26 Jun 2017, 08:34 PM
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.
0
Jacky
Top achievements
Rank 1
answered on 26 Jun 2017, 08:57 PM

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]);
}
}

0
Jacky
Top achievements
Rank 1
answered on 28 Jun 2017, 05:28 PM
if  previous Item is gantt's grandchild, it can't be set to select item?
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 29 Jun 2017, 11:21 AM
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.
Tags
GanttView
Asked by
Jacky
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Jacky
Top achievements
Rank 1
Share this question
or