开发者

Sub Menu Item Command MVVM

<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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜