NLogViewer icon indicating copy to clipboard operation
NLogViewer copied to clipboard

Loaded -= _OnLoaded; This line of code seems to cause problems in some cases

Open Jimmy-drod opened this issue 10 months ago • 7 comments

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.

Jimmy-drod avatar Apr 10 '25 02:04 Jimmy-drod

Image

The screenshot shows that NLogViewer triggers _OnUnloaded when switching to another dxdo:DocumentPanel

Jimmy-drod avatar Apr 10 '25 02:04 Jimmy-drod

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

boexler avatar Apr 10 '25 07:04 boexler

It's a bit strange, the parent component of NLogViewer is MainWindow (_ParentWindow),

Image

Image

but when switching to another dxdo:DocumentPanel, it seems that _ParentWindow.FindChildByUid<NLogViewer>(Uid) is null

Image

Jimmy-drod avatar Apr 11 '25 03:04 Jimmy-drod

In my case, I can comment out this line of code to solve the problem,

Image

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

Jimmy-drod avatar Apr 11 '25 03:04 Jimmy-drod

Does the issue still exist? Otherwise, I would close it, or a pull request to support your "DevExpress" library would be appreciated.

boexler avatar Oct 08 '25 08:10 boexler

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.

Jimmy-drod avatar Oct 15 '25 10:10 Jimmy-drod

Could you please check if my latest version resolves the issue? I found another bug that might be the problem.

boexler avatar Oct 15 '25 10:10 boexler