|
7 | 7 | // Copyright(c) Microsoft Corporation.All rights reserved.
|
8 | 8 |
|
9 | 9 | using System.Collections;
|
| 10 | +using System.Collections.Specialized; |
10 | 11 | using System.Windows.Controls;
|
11 | 12 | using Wpf.Ui.Animations;
|
12 | 13 |
|
@@ -82,7 +83,7 @@ public partial class NavigationView
|
82 | 83 | nameof(FooterMenuItemsProperty),
|
83 | 84 | typeof(IList),
|
84 | 85 | typeof(NavigationView),
|
85 |
| - new FrameworkPropertyMetadata(null) |
| 86 | + new FrameworkPropertyMetadata(null, OnFooterMenuItemsPropertyChanged) |
86 | 87 | );
|
87 | 88 |
|
88 | 89 | /// <summary>
|
@@ -513,16 +514,45 @@ private static void OnMenuItemsPropertyChanged(DependencyObject? d, DependencyPr
|
513 | 514 |
|
514 | 515 | if (navigationView.MenuItemsItemsControl is null)
|
515 | 516 | {
|
| 517 | + navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList); |
516 | 518 | return;
|
517 | 519 | }
|
518 | 520 |
|
519 | 521 | if (navigationView.MenuItemsItemsControl.ItemsSource.Equals(enumerableNewValue))
|
520 | 522 | {
|
| 523 | + navigationView.UpdateMenuItemsTemplate(enumerableNewValue); |
521 | 524 | return;
|
522 | 525 | }
|
523 | 526 |
|
524 | 527 | navigationView.MenuItemsItemsControl.ItemsSource = null;
|
525 | 528 | navigationView.MenuItemsItemsControl.ItemsSource = enumerableNewValue;
|
| 529 | + navigationView.UpdateMenuItemsTemplate(enumerableNewValue); |
| 530 | + navigationView.AddItemsToDictionaries(enumerableNewValue); |
| 531 | + |
| 532 | + navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList); |
| 533 | + } |
| 534 | + |
| 535 | + private void UpdateCollectionChangedEvent(IList? oldMenuItems, IList? newMenuItems) |
| 536 | + { |
| 537 | + if(oldMenuItems is INotifyCollectionChanged notifyCollection) |
| 538 | + { |
| 539 | + notifyCollection.CollectionChanged -= OnMenuItems_CollectionChanged; |
| 540 | + } |
| 541 | + if(newMenuItems is INotifyCollectionChanged newNotifyCollection) |
| 542 | + { |
| 543 | + newNotifyCollection.CollectionChanged += OnMenuItems_CollectionChanged; |
| 544 | + } |
| 545 | + } |
| 546 | + |
| 547 | + private void OnMenuItems_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) |
| 548 | + { |
| 549 | + if (e.NewItems is null) |
| 550 | + { |
| 551 | + return; |
| 552 | + } |
| 553 | + |
| 554 | + UpdateMenuItemsTemplate(e.NewItems); |
| 555 | + AddItemsToDictionaries(e.NewItems); |
526 | 556 | }
|
527 | 557 |
|
528 | 558 | private static void OnMenuItemsSourcePropertyChanged(
|
@@ -551,6 +581,31 @@ DependencyPropertyChangedEventArgs e
|
551 | 581 | navigationView.FooterMenuItems = enumerableNewValue;
|
552 | 582 | }
|
553 | 583 |
|
| 584 | + private static void OnFooterMenuItemsPropertyChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e) |
| 585 | + { |
| 586 | + if (d is not NavigationView navigationView || e.NewValue is not IList enumerableNewValue) |
| 587 | + { |
| 588 | + return; |
| 589 | + } |
| 590 | + |
| 591 | + if (navigationView.FooterMenuItemsItemsControl is null) |
| 592 | + { |
| 593 | + navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList); |
| 594 | + return; |
| 595 | + } |
| 596 | + |
| 597 | + if (navigationView.FooterMenuItemsItemsControl.ItemsSource.Equals(enumerableNewValue)) |
| 598 | + { |
| 599 | + return; |
| 600 | + } |
| 601 | + |
| 602 | + navigationView.FooterMenuItemsItemsControl.ItemsSource = null; |
| 603 | + navigationView.FooterMenuItemsItemsControl.ItemsSource = enumerableNewValue; |
| 604 | + navigationView.UpdateMenuItemsTemplate(enumerableNewValue); |
| 605 | + navigationView.AddItemsToDictionaries(enumerableNewValue); |
| 606 | + navigationView.UpdateCollectionChangedEvent(e.OldValue as IList, e.NewValue as IList); |
| 607 | + } |
| 608 | + |
554 | 609 | private static void OnPaneDisplayModePropertyChanged(
|
555 | 610 | DependencyObject? d,
|
556 | 611 | DependencyPropertyChangedEventArgs e
|
|
0 commit comments