feat: add function to set selected item from outside and sync to UI.

This commit is contained in:
rabbitism
2024-02-14 11:40:19 +08:00
parent f67a5a313c
commit 122f89fc57
4 changed files with 133 additions and 12 deletions

View File

@@ -265,7 +265,7 @@ public class NavMenuItem: HeaderedSelectingItemsControl
e.Handled = true;
}
protected void SelectItem(NavMenuItem item)
internal void SelectItem(NavMenuItem item)
{
if (item == this)
{
@@ -329,4 +329,24 @@ public class NavMenuItem: HeaderedSelectingItemsControl
return logical != null ? result : @default;
}
internal IEnumerable<NavMenuItem> GetLeafMenus()
{
if (this.ItemCount == 0)
{
yield return this;
yield break;
}
foreach (var child in LogicalChildren)
{
if (child is NavMenuItem item)
{
var items = item.GetLeafMenus();
foreach (var i in items)
{
yield return i;
}
}
}
}
}