I am trying to learn Maui by creating a small application. Part of the application will be getting available comm ports and updating the context menu for selection. For now, I am only trying to add a string to an element and then add the element to the list.
Here is the xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="EgretHUDCompanion.MainPage">
<ContentPage.MenuBarItems>
<MenuBarItem Text="File">
<MenuFlyoutItem Text="Count"
Clicked="OnCounterClicked"/>
</MenuBarItem>
<MenuBarItem Text="Edit">
<MenuFlyoutItem Text="Count"
Clicked="OnCounterClicked"/>
</MenuBarItem>
<MenuBarItem Text="Serial">
<MenuFlyoutItem Text="Refresh Comm Ports" Clicked="RefreshCommPorts"/>
<MenuFlyoutSeparator/>
<MenuFlyoutSubItem Text="Select Port" x:Name="AvailablePortsList">
<MenuFlyoutItem Text="Comm 123"/>
</MenuFlyoutSubItem>
<MenuFlyoutSubItem Text="Task">
<MenuFlyoutItem Text="Get Comm Ports"/>
<MenuFlyoutItem Text="Connect"/>
<MenuFlyoutItem Text="Disconnect"/>
</MenuFlyoutSubItem>
</MenuBarItem>
</ContentPage.MenuBarItems>
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Image
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />
<Label
Text="Hello, World!"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label
Text="Welcome to
.NET Multi-platform App UI"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Here is the method that should be updating the menu list named AvailablePortsList:
private void RefreshCommPorts(object sender, EventArgs e)
{
var ee = new MenuFlyoutItem();
ee.Text = $"Comm {count}";
AvailablePortsList.Add(ee);
//AvailablePortsList.Insert(0, ee);
}
Each time this method runs, AvaillablePortsList has an additional element, but the UI does not update.
I assume I am missing some sort of UI update call?
Any help would be appreciated.