Skip to content

Commit

Permalink
Merge pull request #32 from dojo90/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
djonasdev committed Oct 8, 2020
2 parents 1845bd9 + ad4652c commit a5707ff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/NLogViewer/NLogViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ public NLogViewer()
private void _OnUnloaded(object sender, RoutedEventArgs e)
{
// look in logical and visual tree if the control has been removed
// If there is no parent window found before, we have a special case (https://github.com/dojo90/NLogViewer/issues/30) and just dispose it anyway
if (_ParentWindow.FindChildByUid<NLogViewer>(Uid) == null)
{
_Dispose();
Expand All @@ -498,8 +499,14 @@ private void _OnLoaded(object sender, RoutedEventArgs e)
Loaded -= _OnLoaded;

// add hook to parent window to dispose subscription
_ParentWindow = Window.GetWindow(this);
_ParentWindow.Closed += _ParentWindowOnClosed;
// use case:
// NLogViewer is used in a new window inside of a TabControl. If you switch the TabItems,
// the unloaded event is called and would dispose the subscription, even if the control is still alive.
if (Window.GetWindow(this) is { } window)
{
_ParentWindow = window;
_ParentWindow.Closed += _ParentWindowOnClosed;
}

ListView.ScrollToEnd();
var target = CacheTarget.GetInstance(targetName: TargetName);
Expand Down

0 comments on commit a5707ff

Please sign in to comment.