lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.47k stars 725 forks source link

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

Closed ASir-Yiyou closed 4 months ago

ASir-Yiyou commented 5 months ago

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);

}

SlimeNull commented 5 months ago

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

nabeelio commented 5 months ago

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

nabeelio commented 5 months ago

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

m0lDaViA commented 4 months ago

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