Skip to content

Commit

Permalink
Merge pull request #964 from scanfing/development
Browse files Browse the repository at this point in the history
Update NavigationView.Properties.cs
  • Loading branch information
pomianowski authored Mar 13, 2024
2 parents 5e115e8 + 2b5e75e commit e052220
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/Wpf.Ui/Controls/NavigationView/NavigationView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Copyright(c) Microsoft Corporation.All rights reserved.

using System.Collections;
using System.Collections.Specialized;
using System.Windows.Controls;
using Wpf.Ui.Animations;

Expand Down Expand Up @@ -82,7 +83,7 @@ public partial class NavigationView
nameof(FooterMenuItemsProperty),
typeof(IList),
typeof(NavigationView),
new FrameworkPropertyMetadata(null)
new FrameworkPropertyMetadata(null, OnFooterMenuItemsPropertyChanged)
);

/// <summary>
Expand Down Expand Up @@ -513,16 +514,45 @@ private static void OnMenuItemsPropertyChanged(DependencyObject? d, DependencyPr

if (navigationView.MenuItemsItemsControl is null)
{
navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList);
return;
}

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

navigationView.MenuItemsItemsControl.ItemsSource = null;
navigationView.MenuItemsItemsControl.ItemsSource = enumerableNewValue;
navigationView.UpdateMenuItemsTemplate(enumerableNewValue);
navigationView.AddItemsToDictionaries(enumerableNewValue);

navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList);
}

private void UpdateCollectionChangedEvent(IList? oldMenuItems, IList? newMenuItems)
{
if(oldMenuItems is INotifyCollectionChanged notifyCollection)
{
notifyCollection.CollectionChanged -= OnMenuItems_CollectionChanged;
}
if(newMenuItems is INotifyCollectionChanged newNotifyCollection)
{
newNotifyCollection.CollectionChanged += OnMenuItems_CollectionChanged;
}
}

private void OnMenuItems_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (e.NewItems is null)
{
return;
}

UpdateMenuItemsTemplate(e.NewItems);
AddItemsToDictionaries(e.NewItems);
}

private static void OnMenuItemsSourcePropertyChanged(
Expand Down Expand Up @@ -551,6 +581,31 @@ DependencyPropertyChangedEventArgs e
navigationView.FooterMenuItems = enumerableNewValue;
}

private static void OnFooterMenuItemsPropertyChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e)
{
if (d is not NavigationView navigationView || e.NewValue is not IList enumerableNewValue)
{
return;
}

if (navigationView.FooterMenuItemsItemsControl is null)
{
navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList);
return;
}

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

navigationView.FooterMenuItemsItemsControl.ItemsSource = null;
navigationView.FooterMenuItemsItemsControl.ItemsSource = enumerableNewValue;
navigationView.UpdateMenuItemsTemplate(enumerableNewValue);
navigationView.AddItemsToDictionaries(enumerableNewValue);
navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList);
}

private static void OnPaneDisplayModePropertyChanged(
DependencyObject? d,
DependencyPropertyChangedEventArgs e
Expand Down

0 comments on commit e052220

Please sign in to comment.