Skip to content

Commit 4d8d879

Browse files
committed
Close #65
1 parent 647bbca commit 4d8d879

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System;
1+
using NETworkManager.ViewModels;
22

33
namespace NETworkManager.Controls
44
{
5-
public class DragablzRemoteDesktopTabItem : IDisposable
5+
public class DragablzRemoteDesktopTabItem : ViewModelBase
66
{
77
public string Header { get; set; }
88
public RemoteDesktopControl Control { get; set; }
@@ -12,24 +12,5 @@ public DragablzRemoteDesktopTabItem(string header, RemoteDesktopControl control)
1212
Header = header;
1313
Control = control;
1414
}
15-
16-
private bool _disposed;
17-
18-
protected virtual void Dispose(bool disposing)
19-
{
20-
if (_disposed)
21-
return;
22-
23-
if (disposing)
24-
Control.OnClose();
25-
26-
_disposed = true;
27-
}
28-
29-
public void Dispose()
30-
{
31-
Dispose(true);
32-
GC.SuppressFinalize(this);
33-
}
3415
}
3516
}

Source/NETworkManager/Controls/DragablzTabHostWindow.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@
1010
<Controls:MetroWindow.WindowButtonCommands>
1111
<Controls:WindowButtonCommands Template="{DynamicResource MahApps.Metro.Templates.WindowButtonCommands.Win10}" />
1212
</Controls:MetroWindow.WindowButtonCommands>
13-
<Grid Margin="10">
13+
<Grid>
1414
<dragablz:TabablzControl Name="TabsContainer">
1515
<dragablz:TabablzControl.InterTabController>
1616
<dragablz:InterTabController></dragablz:InterTabController>
1717
</dragablz:TabablzControl.InterTabController>
1818
<dragablz:TabablzControl.Style>
19-
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource DefaultTabablzControl}">
19+
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource DefaultTabablzControl}">
2020
<!-- If not null, the header suffix will be removed in the main window -->
2121
<Setter Property="HeaderSuffixContent" Value="{x:Null}" />
22+
<Setter Property="ContentTemplate">
23+
<Setter.Value>
24+
<DataTemplate>
25+
<ContentPresenter Content="{Binding Control}" />
26+
</DataTemplate>
27+
</Setter.Value>
28+
</Setter>
2229
</Style>
2330
</dragablz:TabablzControl.Style>
2431
</dragablz:TabablzControl>

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
using System.Windows.Input;
88
using System;
99
using System.Windows.Threading;
10+
using System.Diagnostics;
1011

1112
namespace NETworkManager.Controls
1213
{
13-
14+
1415
public partial class RemoteDesktopControl : UserControl, INotifyPropertyChanged
1516
{
1617
#region PropertyChangedEventHandler
@@ -23,6 +24,8 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
2324
#endregion
2425

2526
#region Variables
27+
private bool _initialized = false;
28+
2629
private const string RemoteDesktopDisconnectReasonIdentifier = "String_RemoteDesktopDisconnectReason_";
2730

2831
private RemoteDesktopSessionInfo _rdpSessionInfo;
@@ -112,13 +115,24 @@ public RemoteDesktopControl(RemoteDesktopSessionInfo info)
112115

113116
reconnectAdjustScreenTimer.Tick += ReconnectAdjustScreenTimer_Tick;
114117
reconnectAdjustScreenTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
118+
119+
Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
115120
}
116121

117122
private void UserControl_Loaded(object sender, RoutedEventArgs e)
118123
{
119-
if (!Connected)
124+
// Connect after the control is drawn and only on the first init
125+
if (!_initialized)
126+
{
120127
Connect();
121-
}
128+
_initialized = true;
129+
}
130+
}
131+
132+
private void Dispatcher_ShutdownStarted(object sender, EventArgs e)
133+
{
134+
OnClose();
135+
}
122136
#endregion
123137

124138
#region ICommands & Actions
@@ -348,7 +362,7 @@ private void ReconnectAdjustScreenTimer_Tick(object sender, EventArgs e)
348362

349363
// Reconnect with new resulution
350364
ReconnectAdjustScreen();
351-
}
365+
}
352366
#endregion
353367
}
354368
}

Source/NETworkManager/ViewModels/Applications/RemoteDesktopViewModel.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public RemoteDesktopViewModel(IDialogCoordinator instance)
106106
InterTabClient = new DragablzMainInterTabClient();
107107
TabItems = new ObservableCollection<DragablzRemoteDesktopTabItem>();
108108

109-
TabItems.CollectionChanged += TabItems_CollectionChanged;
110-
111109
// Load sessions
112110
if (RemoteDesktopSessionManager.Sessions == null)
113111
RemoteDesktopSessionManager.Load();
@@ -397,16 +395,5 @@ private async void DeleteSessionAction()
397395
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
398396
}
399397
#endregion
400-
401-
#region Events
402-
private void TabItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
403-
{
404-
if (e.Action == NotifyCollectionChangedAction.Remove)
405-
{
406-
DragablzRemoteDesktopTabItem item = (DragablzRemoteDesktopTabItem)e.OldItems[0];
407-
item.Dispose();
408-
}
409-
}
410-
#endregion
411398
}
412399
}

0 commit comments

Comments
 (0)