wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

When modifying the MenuItemsSource of the NavigationView component, the NavigationView will not re-render

Open ASir-Yiyou opened this issue 10 months ago • 3 comments

Describe the bug

When modifying the MenuItemsSource of the NavigationView component, the NavigationView will not re-render

To Reproduce

Use the Demo project to test, the code is as follows: public partial class MainWindowViewModel : ObservableObject { [ObservableProperty] private string _applicationTitle = "WPF UI Gallery";

[ObservableProperty]
private ICollection<object> _menuItems = new ObservableCollection<object>
{
    new NavigationViewItem("Home", SymbolRegular.Home24, typeof(DashboardPage)),
};

[ObservableProperty]
private ICollection<object> _footerMenuItems = new ObservableCollection<object>()
{
};

[ObservableProperty]
private ObservableCollection<Wpf.Ui.Controls.MenuItem> _trayMenuItems =
    new()
    {
    };
public MainWindowViewModel()
{
    Test();
}

private async void Test()
{
    await Task.Delay(2000).ConfigureAwait(true);
    Application.Current.Dispatcher.Invoke(() =>
    {
        MenuItems = new ObservableCollection<object>
        {
           new NavigationViewItem("Content", SymbolRegular.Home12, typeof(DashboardPage)),
        };
    });
}

} The page cannot render the NavigationView options

Expected behavior

Page re-render NavigationView

Screenshots

No response

OS version

Windows

.NET version

.NET8.0-windows

WPF-UI NuGet version

3.0.0

Additional context

Code Modify OnMenuItemsPropertyChanged Event:The page can be re-rendered NavigationView private static void OnMenuItemsPropertyChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e) { if (d is not NavigationView navigationView || e.NewValue is not IList enumerableNewValue) { return; }

if (navigationView.MenuItemsItemsControl is null)
{
    return;
}

if (navigationView.MenuItemsItemsControl.ItemsSource.Equals(enumerableNewValue))
{
    return;
}

navigationView.MenuItemsItemsControl.ItemsSource = null;
navigationView.MenuItemsItemsControl.ItemsSource = enumerableNewValue;
OnItemTemplatePropertyChanged(d, e);

}

ASir-Yiyou avatar Apr 11 '24 01:04 ASir-Yiyou

This bug is already fixed in the latest version, update your package version.

SlimeNull avatar Apr 14 '24 11:04 SlimeNull

Doesn't seem to be fixed on my end - my code is essentially the same

nabeelio avatar Apr 29 '24 19:04 nabeelio

Nevermind, I have to replace the ObservableCollection with a new copy for it to swap

nabeelio avatar Apr 29 '24 19:04 nabeelio

@ASir-Yiyou If this is solved for you, please close this issue.

m0lDaViA avatar May 08 '24 12:05 m0lDaViA