Search code examples
wpfwindowsmodern-ui

Clear Navigation Stack mui wpf


I'm very new to wpf, right now, I'm using ModernUI version 1.0.6 I'm searching for a way to clear the navigation history for modernwindow. Or the way to remove the navigation button out of the modernwindow would also appreciated.


Solution

  • You can try to read the source code of mui, and you will find smoe way to clear. First you can try reflect the ModernFrame class to get history field, then you can invoke Clear() where you want, and code like this:

    var frame = view.FindChild<ModernFrame>("ContentFrame");
    var field = typeof(ModernFrame).GetField("history", BindingFlags.NonPublic | BindingFlags.Instance);
    var history = (Stack<Uri>)field.GetValue(frame);
    
    history.Clear();
    

    Second you can find DependencyProperty KeepContentAlive in the ModernFrame class, this property has a propertyChangedCallback, so the navigation history will clear if its value changed. To do this you need to rewrite ModernWindow's style and binding a property with KeepContentAlive from vm.