开发者

Sub Menu Item Command MVVM

开发者 https://www.devze.com 2023-01-21 21:40 出处:网络
<MenuItem Header=\"Flag(s)\" ItemsSource=\"{Binding Path=LineItemFlags}\" Command=\"{Binding AssignFollowupCommand}\">
<MenuItem Header="Flag(s)" ItemsSource="{Binding Path=LineItemFlags}" Command="{Binding AssignFollowupCommand}">
    <MenuItem.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding FlagName}">    
            </TextBlock>
        </DataTemplate>
    </MenuItem.ItemTemplate>
</MenuItem>

For the parent Item i mean 开发者_开发百科menu item i have a command it's invoking i want to know how to setup command for Sub Menu item


Rather than setting the ItemTemplate, set the ItemContainerStyle. Give it a style that sets the Header and Command properties of the menu item.

<MenuItem Header="_Recent Files" ItemsSource="{Binding RecentFiles}">
    <MenuItem.ItemContainerStyle>
        <Style>
            <Setter Property="MenuItem.Header" Value="{Binding FileName}"/>
            <Setter Property="MenuItem.Command" Value="{Binding Open}"/>
        </Style>
    </MenuItem.ItemContainerStyle>
</MenuItem>

Full example and description on Code Project.

0

精彩评论

暂无评论...
验证码 换一张
取 消