dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.22k stars 1.75k forks source link

Mac Catalyst bindable properties not updating after being set #21417

Open beeradmoore opened 7 months ago

beeradmoore commented 7 months ago

Description

When you have a MenuBarItem or FlyoutItem and bind its Text or IsEnabled (probably more) and you toggle those values it does not update the menu itself after initial binding.

<MenuBarItem Text="{Binding MenuBarItemText}" x:DataType="local:MainPageModel">
    <MenuFlyoutItem Text="{Binding MenuFlyoutItemText}" />
    <MenuFlyoutItem Text="Enabled on odd clicks" IsEnabled="{Binding IsOddClicks}" />
</MenuBarItem>

In the sample repo I created any changes to MenuBarItemText, MenuFlyoutItemText, and IsOddClicks (by clicking the button on the page) does not get reflected in the UI when tested on macOS. This works as expected on Windows.

I don't think this is a regression, this has been broken at least since 8.0.6, it may have never worked.

Example

macOS - see how clicks is 5 but the menu is not updated.

Screenshot 2024-03-25 at 7 03 43 PM

Screenshot 2024-03-25 at 7 03 54 PM

Windows: image

image

Steps to Reproduce

  1. Create new MAUI application
  2. Add some sort of string value that can be binding to (I used CommunityToolkit.MVVM
  3. Use that string in a menu item
  4. Update the string
  5. Observe menu item did not update
  6. Launch application on Windows
  7. Update the string
  8. Observe menu item DID update

Link to public reproduction project repository

https://github.com/beeradmoore/maui-issue-MenuBarTextEnabledBindingIssue

Version with bug

8.0.14

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

macOS 14.4

Did you find any workaround?

Not yet

Relevant log output

No response

ninachen03 commented 7 months ago

Can repro it at maccatalyst on the latest 17.6.10(build428)(8.0.14).

beeradmoore commented 7 months ago

Just noticed an interesting thing that I'll see if I can add into the repro.

In my actual app I have a File > Import menu. Clicking Import opens a file browser. Closing that file browser left the File > Import menu disabled where it was previously enabled. I am also using RelayCommand from CommunityToolkit.MVVM over there. And my method is async/awaitable.

Initial thoughts there is that whatever is doing the Commanding and controlling CanExecute seems to update the IsEnabled correctly, but binding my own property with ObservableProperty isn't triggering the same thing.

AlexVDV116 commented 5 months ago

Can confirm the same bug happens using a MenuFlyoutItem in a MenuFlyOut on MacCatalyst on Vesion 8.0.21.

<FlyoutBase.ContextFlyout>
    <MenuFlyout x:DataType="entities:LogEntry">
        <MenuFlyoutItem Command="{Binding Source={RelativeSource AncestorType={x:Type viewModels:LogEntriesViewModel}}, Path=PinLogEntryCommand}" CommandParameter="{Binding .}"
                        Text="{Binding IsPinned, Converter={StaticResource BoolToPinTextConverter}}" />
    </MenuFlyout>
</FlyoutBase.ContextFlyout>