Search code examples
c#wpfmvvmnlogavalondock

why do items disappear when i redock the window?


i tried printing out to a listbox the nlog exceptions using NLog Viewer in avalon dock window

If i try to dock out the window the listbox is cleared out and its the same for docking the window with the listbox back.

How could i fix that?

xaml code

 <Grid>
        <StackPanel Margin="0,10">
            <Grid Visibility="{Binding outputVisibility, UpdateSourceTrigger=PropertyChanged}">
                <nlog:NlogViewer x:Name="logCtrl"  MinHeight="300" MinWidth="1000"/>
            </Grid>

            <Button Command="{Binding ConvertTextCommand}" Margin="5" Height="35">PrintException</Button>
            <Button Command="{Binding HideTextBoxCommand}" Margin="5">Hide</Button>
        </StackPanel>
    </Grid>

nlog config file

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <extensions>
    <add assembly="NlogViewer" />
  </extensions>
  <targets>
    <target xsi:type="NlogViewer" name="ctrl" />
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="ctrl" />
  </rules>
</nlog>

And I m using this to simulate exceptions.

try
            {
                counter++;
                if (counter % 2 == 0)
                    throw new OutOfMemoryException();
                else throw new ArgumentOutOfRangeException();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.StackTrace + " " + ex.Message);
            }

UPDATE

I also noticed that even a simple text box with text will get cleared out after dock out or dock in


Solution

  • I found that the issue was xceed avalon dock community version.

    There is an issue about dockable pane reloading in xceed github project and they added a function to retain the info in the pane after docking in the premium version.

    I solved this issue using Avalon Dock.

    From my understanding this is a branch of the xceed project but with much more development. I just downloaded this with nuget package manager and uninstalled xceed avalon dock. Now the items are saved after dock in dock out