How to correctly bind menu items?

前端 未结 1 697
醉话见心
醉话见心 2021-01-02 11:20

How do i correctly bind a dynamical created list of menu items. I have tried several thing but none seem to work. I get the proper list of names, however my ViewSwitchComm

相关标签:
1条回答
  • 2021-01-02 12:20

    This code works for me:

    <MenuItem Header="Names" ItemsSource="{Binding Player.ToonNames}">
        <MenuItem.ItemContainerStyle>
            <Style TargetType="MenuItem">
                <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.ViewSwitchCommand}" />
                <Setter Property="CommandParameter" Value="{Binding}" />
            </Style>
        </MenuItem.ItemContainerStyle>
    </MenuItem>
    
    0 讨论(0)
提交回复
热议问题