Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuFlyout ItemsSource item binding command always disabled #15689

Open
29654761 opened this issue May 11, 2024 · 7 comments
Open

MenuFlyout ItemsSource item binding command always disabled #15689

29654761 opened this issue May 11, 2024 · 7 comments

Comments

@29654761
Copy link

29654761 commented May 11, 2024

Describe the bug

After I upgrade to 11.1.0-beta2, all my menu items are disabled.

To Reproduce

<Button ToolTip.Tip="摄像头">
    <Image Source="avares:/Assets/Images/btn_camera.png" />
    <Button.Flyout>
        <MenuFlyout ItemsSource="{Binding VideoDevItems}" Opening="MenuVideo_Opening" />
    </Button.Flyout>
    <Button.Styles>
        <Style Selector="MenuItem" x:DataType="models:VideoDeviceViewModel">
            <Setter Property="Header" Value="{Binding Text}"/>
            <Setter Property="Command" Value="{Binding #PART_Frame.SelectVideoDevice}" />
            <Setter Property="CommandParameter" Value="{Binding}" />
            <Setter Property="Icon">
                <Template>
                    <Image Source="avares:/Assets/Images/checked.png" IsVisible="{Binding IsSelected}" />
                </Template>
            </Setter>
        </Style>
    </Button.Styles>
</Button>

The menu items are always disabled.

If I remove

<Setter Property="Command" Value="{Binding #PART_Frame.SelectVideoDevice}" />

MenuItem will be enabled.

This code is work fine on 11.0.10,

Expected behavior

No response

Avalonia version

11.1.0-beta2

OS

Windows

Additional context

No response

@grokys
Copy link
Member

grokys commented May 14, 2024

Hi @29654761 - I've tried to reproduce your problem but unfortunately I don't have enough information to be able to do so. For example, the #PART_Frame control that is the source of your command isn't included in your example code.

Would you be able to create a minimal repro in the form of a GitHub repository or a .zip file that I can run?

In addition are you seeing any binding errors being logged?

@29654761
Copy link
Author

I Created a new project and copy code, but it works ok.
The raw project is created from old version, I tried to figure out the diffence,
I found out remove the below line in csproj file can work fine.

<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>

@timunie
Copy link
Contributor

timunie commented May 21, 2024

@29654761 that means you are having a DataContext issue most likely. You may need to cast or sprcify x:DataType

See: https://docs.avaloniaui.net/docs/basics/data/data-binding/compiled-bindings

Note

If you upload a minimal sample and we verify it is an issue, I'll reopen this issue.

@timunie timunie closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
@timunie timunie added by-design The behavior reported in the issue is actually correct. and removed bug regression labels May 21, 2024
@29654761
Copy link
Author

AvaloniaApplication1.zip

@timunie This minimal sample can reproduce the issue.

@29654761 that means you are having a DataContext issue most likely. You may need to cast or sprcify x:DataType

See: https://docs.avaloniaui.net/docs/basics/data/data-binding/compiled-bindings

Note

If you upload a minimal sample and we verify it is an issue, I'll reopen this issue.

@rabbitism
Copy link
Contributor

image

@29654761
Copy link
Author

AvaloniaApplication1.zip
Sorry , I uploaded again.

@timunie timunie reopened this May 23, 2024
@timunie timunie added bug and removed needs-repro by-design The behavior reported in the issue is actually correct. labels May 23, 2024
@timunie
Copy link
Contributor

timunie commented May 23, 2024

The repo is great. Points out, it works if:

  • I use ReflectionBinding
  • of I use an ICommand instead of void
  • or I consume the void from outside the Popup.

No clue why, but maybe @grokys has an idea where to look at. No priorty issue, as we have enough ways to make the same thing working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants