wpfui
wpfui copied to clipboard
When modifying the MenuItemsSource of the NavigationView component, the NavigationView will not re-render
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
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);
}
This bug is already fixed in the latest version, update your package version.
Doesn't seem to be fixed on my end - my code is essentially the same
Nevermind, I have to replace the ObservableCollection
with a new copy for it to swap
@ASir-Yiyou If this is solved for you, please close this issue.