1

In my WPF project I have a TabControl with several tab items. Each Tab Item has a WPF control (view) and each view has a correspondent ViewModel. Each time I click to change tab item I noticed that the control/view is unload and loaded again when I click the tab item again, the correspondent ViewModel stays in memory.

I m trying t build a simple RemoteDesktop/RDP client that uses 1 tab item per computer connection, so the problem is when I change tab item, the connection goes away because the view is unloaded...

I researched for some examples out there, but most of them are built in top of Winforms that has a different implementation from WPF.

So I was thinking if it is possible to prevent the View from going out of scope when I change from TabItem?

Does Any one knows about some sample online that uses WPF for tabbed RDP connections? Thank you.

UPDATE - DataTemplate being used

<DataTemplate DataType="{x:Type vm:DashboardViewModel}">
        <v:DashboardView />
</DataTemplate>
J_PT
  • 479
  • 4
  • 22

1 Answers1

0

I found a solution here

WPF TabControl - Preventing Unload on Tab Change?

replace

      <TabItem Header="Tab1" Content="{Binding Tab1ViewModel}" />
by

        <TabItem Header="Tab1">
            <ContentPresenter Content="{Binding Tab1ViewModel}" />
        </TabItem>
Community
  • 1
  • 1
J_PT
  • 479
  • 4
  • 22