24 HDreams

24 HDreams

  • NA
  • 9
  • 736

MetroTabItem View Going out of Scope

Dec 13 2016 7:11 PM
I have a MetroTabControl that I want to use to display several RDP connections using the TabItems, the problem that I`m having is, after I establish the first RDP connection, If I switch tabItem, the view goes out of scope and I loose the connection in that TabItem (so each time I switch tabitem the view goes out of scope). I wanted to maintain the connection alive in each TabItem and control the close of the view with the CloseTabCommand using the tabitem CloseButton.
In this sample the RemoteClients is an Observable collection of an objectClass that each TabItem will bind to
e.g. ObservableCollection<RdpClient>RemoteClients{get; set;}
The SelectedRemoteClient represents the current selected object (RdpClient).
RemoteDesktopBaseControlView is the view that each TabItem will have and has all the bindings for the RdpClient object
 
<Grid>
<controls:MetroTabControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding RemoteClients, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedRemoteClient, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
CloseTabCommand="{Binding CloseTabCommand}" >
<controls:MetroTabControl.Resources>
<DataTemplate x:Key="contentTemplate" x:Shared="False">
<RemoteDesktopBaseControlView />
</DataTemplate>
</controls:MetroTabControl.Resources>
<controls:MetroTabControl.ItemContainerStyle>
<Style TargetType="{x:Type controls:MetroTabItem}">
<Setter Property="Header" Value="{Binding Name, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="controls:MetroTabItem.ContentTemplate" Value="{StaticResource contentTemplate}"/>
<Setter Property="controls:MetroTabItem.CloseButtonEnabled" Value="True"/>
<Setter Property="controls:MetroTabItem.CloseTabCommandParameter" Value="{Binding}" />
<Setter Property="controls:ControlsHelper.HeaderFontSize" Value="16" />
<Setter Property="controls:ControlsHelper.HeaderMargin" Value="4" />
</Style>
</controls:MetroTabControl.ItemContainerStyle>
</controls:MetroTabControl>
</Grid>
 
Any Ideas how to fix this?

Answers (1)