Loaded -= _OnLoaded; This line of code seems to cause problems in some cases
private void _OnLoaded(object sender, RoutedEventArgs e) { // removed loaded handler to prevent duplicate subscribing Loaded -= _OnLoaded;
Assume that a dxdo:DocumentGroup contains two dxdo:DocumentPanel, and continue to assume that NLogViewer is placed under one of the dxdo:DocumentPanels. Switching to another dxdo:DocumentPanels will trigger _OnUnloaded of NLogViewer. Then switching back will cause _OnLoaded to no longer be triggered because of the above code Loaded -= _OnLoaded;, so the log will no longer be displayed.
The screenshot shows that NLogViewer triggers _OnUnloaded when switching to another dxdo:DocumentPanel
Will the Dispose() method also be called in this case? For this special case, the ParentWindow should have been set beforehand to prevent a Dispose().
see: https://github.com/djonasdev/NLogViewer/blob/master/src/NLogViewer/NLogViewer.xaml.cs#L503
It's a bit strange, the parent component of NLogViewer is MainWindow (_ParentWindow),
but when switching to another dxdo:DocumentPanel, it seems that _ParentWindow.FindChildByUid<NLogViewer>(Uid) is null
In my case, I can comment out this line of code to solve the problem,
because in my case, NLogViewer is created together with MainWindow, and its life cycle is consistent with MainWindow. Finally, when MainWindow is closed, it triggers __ParentWindow.Closed += ParentWindowOnClosed; and recycles NLogViewer at the same time
Does the issue still exist? Otherwise, I would close it, or a pull request to support your "DevExpress" library would be appreciated.
Yes, you can close this issue. I just commented out this line in the program: Unloaded += _OnUnloaded;. This works for my program. I haven't found the real reason, I'd better not make a pull request.
Could you please check if my latest version resolves the issue? I found another bug that might be the problem.