AvaloniaUI/Avalonia

Binding inside MenuFlyout inside TemplatedControl does not work the first time

Opened this issue · 1 comments

Describe the bug

On our project, we use a MenuFlyout on a Button in a TemplatedControl that is dynamically modified based on another binding property.
The first time the button is pressed on each TemplatedControl, the Bindings in he MenuFlyout are not bound correctly. After the second time each button is pressed, everything works as expected.

First time:
Screenshot from 2024-12-04 08-51-06

Second time:
Screenshot from 2024-12-04 08-53-49

To Reproduce

https://github.com/Trueber/template-binding-isse/blob/master/TemplatedControlBindingIssue/Controls/TemplatedControl1.axaml

 <Button >
        <avalonia:MaterialIcon Foreground="Gray" Kind="Menu" MinHeight="48" MinWidth="48" />
        <Button.Flyout>
            <MenuFlyout>
                <MenuItem
                    IsVisible="{TemplateBinding MenuItem1Visible}"
                    Header="{TemplateBinding Header1}"
                    Command="{TemplateBinding MenuItem1}"
                    CommandParameter="{TemplateBinding State}">
                </MenuItem>
                <MenuItem
                    IsVisible="{TemplateBinding MenuItem2Visible}"
                    Header="{TemplateBinding Header2}"
                    Command="{TemplateBinding MenuItem2}"
                    CommandParameter="{TemplateBinding State}">
                </MenuItem>
           </MenuFlyout>
         </Button.Flyout>
</Button>

Expected behavior

The Bindings already work on the first time each button is pressed.

Avalonia version

11.x.x

OS

Windows, Linux

Additional context

No response

Has the same problem