Kinnara / ModernWpf

Modern styles and controls for your WPF applications
MIT License
4.44k stars 445 forks source link

Implementing NavigationView in WPF to use as a Powershell GUI #134

Closed IvanDrag0 closed 3 years ago

IvanDrag0 commented 4 years ago

I'm trying to implement a Powershell GUI that uses NavigationView (similarly to how the sample app looks), however, I'm having some trouble getting it to work in a WPF .NET Framework 4.8 project. I've tried following the example app and the example scripts on the MS website, and created the following XAML page:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        xmlns:ui="http://schemas.modernwpf.com/2019"
        ui:WindowHelper.UseModernWindowStyle="True"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ui:ThemeResources />
                <ui:XamlControlsResources />
                <!-- Other merged dictionaries here -->
            </ResourceDictionary.MergedDictionaries>
            <!-- Other app resources here -->
        </ResourceDictionary>
    </Window.Resources>

    <Grid>
        <ui:NavigationView x:Name="NavView" 
                                            Height="Auto"
                                            Header="Nav View" 
                                            PaneDisplayMode="Auto" 
                                            IsTabStop="False" 
                                            SelectionChanged="NavigationView_SelectionChanged5" >
            <ui:NavigationView.MenuItems>
                <ui:NavigationViewItem Content="Menu Item1" Tag="SamplePage1" Icon="Play" />
                <ui:NavigationViewItem Content="Menu Item2" Tag="SamplePage2" Icon="Save" />
                <ui:NavigationViewItem Content="Menu Item3" Tag="SamplePage3" Icon="Refresh" />
                <ui:NavigationViewItem Content="Menu Item4" Tag="SamplePage4" Icon="Download" />
            </ui:NavigationView.MenuItems>
            <ui:Frame Margin="0,0,0,0" x:Name="contentFrame" />
        </ui:NavigationView>
    </Grid>
</Window>

But I'm getting the following error: "Specified cast is not valid." with the following error in the designer:

InvalidCastException: Specified cast is not valid.

StackTrace

at ModernWpf.Controls.NavigationView.GetPaneToggleButtonHeight()
   at ModernWpf.Controls.NavigationView.UpdateBackAndCloseButtonsVisibility()
   at ModernWpf.Controls.NavigationView.UpdateIsClosedCompact()
   at ModernWpf.Controls.NavigationView.OnSplitViewClosedCompactChanged(DependencyObject sender, DependencyProperty args)
   at ModernWpf.Controls.SplitView.OnDisplayModePropertyChanged(DependencyPropertyChangedEventArgs args)
   at ModernWpf.Controls.SplitView.OnDisplayModePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at ModernWpf.Controls.NavigationView.UpdateVisualStateForDisplayModeGroup(NavigationViewDisplayMode displayMode)
   at ModernWpf.Controls.NavigationView.SetDisplayMode(NavigationViewDisplayMode displayMode, Boolean forceSetDisplayMode)
   at ModernWpf.Controls.NavigationView.UpdateAdaptiveLayout(Double width, Boolean forceSetDisplayMode)
   at ModernWpf.Controls.NavigationView.UpdatePaneDisplayMode()
   at ModernWpf.Controls.NavigationView.OnApplyTemplate()
   at System.Windows.FrameworkElement.ApplyTemplate()
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)

I can use other controls and create GUIs with no issue, however, the NavView control is the only one that I can't seem to figure out. Is there a way to get the control working with the NavView control? or is this control unique in that regard?

Kinnara commented 4 years ago

I believe this has been fixed by #123. I'll try to release a new version soon.

IvanDrag0 commented 4 years ago

Thank you!

Just pulled the latest master branch and compiled it, and looks like the fix worked! :)

ShankarBUS commented 3 years ago

@Kinnara, this issue could be closed.