1
我是wpf世界的新手。我在下面的殼上下文菜單:帶棱鏡的mvvm:從菜單項設置視圖
<ContextMenu>
<MenuItem Header="Login"
Command="{Binding WorkSpaceViewSetter}" CommandParameter="DemoApplication.View.LoginView">
<MenuItem.Icon>
<Image Height="16" Width="16" Stretch="Uniform" Source="/Images/login.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Modules" ItemsSource="{Binding AppModules}">
<MenuItem.Icon>
<Image Source="/Images/modules.png"/>
</MenuItem.Icon>
<MenuItem.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header" Value="{Binding ModuleName}"/>
<Setter Property="Command" Value="{Binding ElementName=win, Path=DataContext.WorkSpaceViewFromType}"/>
<Setter Property="CommandParameter" Value="{Binding MainViewType}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
</ContextMenu>
在模塊的的ItemsSource AppModules
每個元素菜單項中有一個名爲System.Type
類型的MainViewType
財產。當菜單項被點擊並且正在考慮在shellviewmodel
中使用單個ICommad
並將MainViewType
作爲命令參數傳遞時,我想要更改區域的視圖。但是,上述代碼不起作用。 我想知道爲什麼Modules
menuitem按照預期從itemssource
填充。
我注意到Login
menuitem上的命令綁定也不起作用,即使它應該有,因爲Modules
的itemssource
屬性得到了正確的界定。任何人都可以請建議如何使它工作?
什麼是ICommand的Execute的樣子? –
我使用Microsoft.Practices.Prism.Commands的DelegateCommand。 –