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

Command binding losses when using DropDownButton #4494

Open
furqansafdar opened this issue Jun 20, 2024 · 0 comments
Open

Command binding losses when using DropDownButton #4494

furqansafdar opened this issue Jun 20, 2024 · 0 comments
Labels

Comments

@furqansafdar
Copy link

furqansafdar commented Jun 20, 2024

Describe the bug

Seems to have found a bug when using DropDownButton, command binding is lost when navigate away and comes back.

Context: I am using Prism Library and have different views with same definition of DropDownButton w.r.t to each category. When view is loaded the first time it works fine but when navigate away to another view and comes back it stops working even for others as well.

The issue I'm encountering seems to be related to the fact that the MenuItem instances within the dropdown's ContextMenu are not within the same logical tree as the rest of your control, which might be causing binding issues.

<mah:DropDownButton
    x:Name="BtnAdd"
    Content="Add"
    ItemTemplate="{StaticResource DropDownButtonDataTemplate}"
    ItemsSource="{Binding Buttons}">
    <mah:DropDownButton.ItemContainerStyle>
        <Style TargetType="MenuItem">
            <Setter Property="Command" Value="{Binding Path=DataContext.AddCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
            <Setter Property="CommandParameter" Value="{Binding Path=Item2}" />
        </Style>
    </mah:DropDownButton.ItemContainerStyle>
</mah:DropDownButton>

Seeking any guidance or workaround to handle this situation?

Environment

MahApps.Metro version: v3.0.0-alpha0492
Windows build number: Win11 23H2
Visual Studio: 2022 17.10.0
Target Framework: .Net 8

Screenshots

image

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

No branches or pull requests

1 participant