以下是我的代码的一个示例:
MainViewModel从顶部/左侧菜单接收消息并显示UserControl
public class MainViewModel : ViewModelBase
{
Messenger.Default.Register<NotificationMessage<string>>(this, "My_Token", (message) =>
{MessageUtility wMesageUtility = new MessageUtility();
switch (message.Notification)
{
case "MyMessage":
switch (message.Content)
{
case "Insert":
if (!SimpleIoc.Default.IsRegistered<Insert_ViewModel>())
{
SimpleIoc.Default.Register<Insert_ViewModel>(true);
}
wInsertVM = SimpleIoc.Default.GetInstance<Insert_ViewModel>();
ShowMainView(null);
CurrentViewModel = wInsertVM;
break;
default:
break;
}
break;
default:
break;
}
});
我的ViewModel类:
public class Insert_ViewModel : ViewModelBase
{
public FormInternal_ViewModel()
{
...Some Code with ICommand and private methods
}
}
我的XAML文件:
<UserControl x:Class="MyApp.UC.Insert"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="700"
>
<DockPanel Name="MainDock" LastChildFill="True" DataContext="{Binding Insert, Source={StaticResource Locator}}"
VerticalAlignment="Stretch"
Height="Auto">
<Grid>
</Grid>
</DockPanel>
</UserControl>
选择顶部/左侧菜单后,如何处置Insert_ViewModel? 谢谢。