-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
MenuFlyoutSubItem.cs
99 lines (82 loc) · 2.22 KB
/
MenuFlyoutSubItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#nullable disable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using Microsoft.Maui.Controls.StyleSheets;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls
{
public partial class MenuFlyoutSubItem : MenuFlyoutItem, IMenuFlyoutSubItem
{
readonly List<IMenuElement> _menus = new List<IMenuElement>();
private protected override IList<Element> LogicalChildrenInternalBackingStore
=> new CastingList<Element, IMenuElement>(_menus);
public IMenuElement this[int index]
{
get { return _menus[index]; }
set
{
RemoveAt(index);
Insert(index, value);
}
}
public int Count => _menus.Count;
public bool IsReadOnly => false;
public void Add(IMenuElement item)
{
var index = _menus.Count;
AddLogicalChild((Element)item);
NotifyHandler(nameof(IMenuBarItemHandler.Add), index, item);
}
public void Clear()
{
for (int i = _menus.Count - 1; i >= 0; i--)
RemoveAt(i);
}
public bool Contains(IMenuElement item)
{
return _menus.Contains(item);
}
public void CopyTo(IMenuElement[] array, int arrayIndex)
{
_menus.CopyTo(array, arrayIndex);
}
public IEnumerator<IMenuElement> GetEnumerator()
{
return _menus.GetEnumerator();
}
public int IndexOf(IMenuElement item)
{
return _menus.IndexOf(item);
}
public void Insert(int index, IMenuElement item)
{
InsertLogicalChild(index, (Element)item);
NotifyHandler(nameof(IMenuFlyoutSubItemHandler.Insert), index, item);
}
public bool Remove(IMenuElement item)
{
var index = _menus.IndexOf(item);
var result = RemoveLogicalChild((Element)item, index);
NotifyHandler(nameof(IMenuFlyoutHandler.Remove), index, item);
return result;
}
public void RemoveAt(int index)
{
var item = _menus[index];
RemoveLogicalChild((Element)item, index);
NotifyHandler(nameof(IMenuFlyoutHandler.Remove), index, item);
}
IEnumerator IEnumerable.GetEnumerator()
{
return _menus.GetEnumerator();
}
void NotifyHandler(string action, int index, IMenuElement view)
{
Handler?.Invoke(action, new Maui.Handlers.MenuFlyoutSubItemHandlerUpdate(index, view));
}
}
}