0

I've got MyDataGrid, derived from DataGrid in ContentTemplate of TabItem:

    <TabControl.ContentTemplate>
        <DataTemplate>
            <MyDataGrid ItemsSource={Binding CurrentTab.Collection}>
                ...
            </MyDataGrid>
        </DataTemplate>
   </TabControl>

(CurrentTab is current model object in my ViewModel and Collection is ObservableCollection). The issue is that when I switch tab item to another and switch back to first one, items that were selected/in view port aren't selected and DataGrid is scrolled to the start.

Also: WPF TabControl and DataGrid bugs, bugs and bugs (first "bug")

Community
  • 1
  • 1
fut33v
  • 3
  • 4
  • Isn't the CurrentTab binding changing when you switch the tab? – Jose Nov 02 '15 at 12:49
  • Yes, `CurrentTab` changes when I switch the tab. – fut33v Nov 02 '15 at 13:58
  • Then I think you are loosing the binding in MyDataGrid ItemSource. Maybe with a little more code will be easier to help. – Jose Nov 02 '15 at 14:02
  • Hmm, don't get it, what means loosing the binding? All the data which should be displayed for different tabs is displayed properly, the issue is loosing selected item and current view port. There is my XAML: http://pastebin.com/vpxB0Dgd – fut33v Nov 02 '15 at 14:20
  • I mean that you are changing the ItemSource of your DataGrid every time you change the tab, maybe this is causing a reInitialization of the grid and then you loose the selected item, because when you init a DataGrid, it hasn't SelectedItem by default. – Jose Nov 02 '15 at 14:42
  • Try binding your itemsource to tab1.Collection, tab2.Collection...Etc, instead of currentTab.Collection. – Jose Nov 02 '15 at 14:48
  • @Kirenenko hmm If I will bind to something like tab1..tab2 there will no sense in that template stuff :D – fut33v Nov 03 '15 at 05:54
  • @Kirenenko may be there is some way to create several DataGrids for each templated tab item... – fut33v Nov 03 '15 at 05:54
  • Then you should give the correspondant tab source when you use the template. Give me some code of the use of the template if you want more explanations. – Jose Nov 03 '15 at 07:39
  • ViewModel: http://pastebin.com/P5PgHSiz, XAML: http://pastebin.com/vpxB0Dgd – fut33v Nov 03 '15 at 07:50
  • There is so much code mate...Im not going to study all of that. I'll give you the clue in a response, maybe it helps. – Jose Nov 03 '15 at 07:57

1 Answers1

0

Use TemplateBinding in your Template, then pass your correspondant Tab or collection when you use it in every tab.

Check this out for more info.

Community
  • 1
  • 1
Jose
  • 1,857
  • 1
  • 16
  • 34