我如何正确绑定一个动态创建的菜单项列表。我尝试了几种方法,但似乎都不起作用。我可以得到正确的名称列表,但我的ViewSwitchCommand似乎没有正确触发。
<MenuItem Foreground="White" Header="Names" ItemsSource="{Binding Player.ToonNames}" Command="{Binding ViewSwitchCommand}" CommandParameter="{Binding Header}"/>
然而,如果我不动态地这样做,而是像这样做,那么一切都能正常工作,可以让它正常工作。
<MenuItem Foreground="White" Header="Names">
<MenuItem Foreground="Black" Header="Chat" Command="{Binding ViewSwitchCommand}" CommandParameter="player1" />
<MenuItem Foreground="Black" Header="Craft" Command="{Binding ViewSwitchCommand}" CommandParameter="player2" />
</MenuItem>
命令参数需要一个字符串,不确定是否是这个问题...希望这只是我忽略的简单问题。