1

我正在 Silverlight 中构建一个具有 4-5 个视图的简单应用程序。我遇到了 MVVM Light 工具包,我认为它适合我的需要。

背景

应用程序将具有典型列表和详细信息显示的视图

  • 制造商
  • 产品

等等,带有左侧导航、页眉和页脚(用户控件)。

我正在考虑在设计时创建一个带有用户控件的主页。

问题

从左侧导航控件中选择链接时,中央面板应使用不同的视图进行更新(如制造商、产品等)

我了解 Messenger 是轻工具包中不同虚拟机之间通信的一种选择。

问题

如何使用 MVVM 轻量级工具包设计我的应用程序。中央窗格需要在运行时加载不同的视图。

我特别关注实现应用程序导航部分的帮助。

谢谢你。

4

1 回答 1

1

我必须以非 mvvm 方式实现基本导航。我有一个消息监听器坐在我的主视图的构造函数上,它监听页面导航消息(自定义消息学习它,喜欢它,使用它)然后它将导航框架的内容源设置为发送的 url信息。我有使用字符串常量的所有页面和子页面导航设置的 URL。

public MainPage()
        {
            InitializeComponent();
            Loaded += OnLoaded;
            WebContext.Current.Authentication.LoggedOut +=
                new EventHandler<System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationEventArgs>(Authentication_LoggedOut);
            Messenger.Default.Register<msgs.NavigationRequest<PageURI>>(this, (uri => ContentFrame.Navigate(uri.Content)));
            Messenger.Default.Register<WavelengthIS.Core.Messaging.ExceptionMessage>(this, ex => ShowExceptionMessage(ex));
            Messenger.Default.Register<WavelengthIS.Core.Messaging.StringMessage>(this, str => ShowMessageForUser(str));

        }


public class PageURI : Uri
    {
        public PageURI(string uriString, UriKind uriKind)
            : base(uriString, uriKind)
        {

        }


    }


public class PageLinks
    {
        public const string SEARCHBYDAYCOUNTVIEW = "/Views/PatientSearchHeaders/SearchByDayCountView.xaml";
        public const string SEARCHBYPATIENTCRITERIAVIEW = "/Views/PatientSearchHeaders/SearchByPatientCriteriaView.xaml";
        public const string QUESTIONAIRRESHELL = "/Views/QuestionairreViews/QuestionairreShell.xaml";
        public const string HOME = "/Views/PrimarySearchView.xaml";
        public const string REPORTS = "/Views/ReportsPage.xaml";
        public const string LOGINPAGE = "/Views/LoginPageView.xaml";
    }

VM中的实际调用:

private void OnSurveyCommandExecute()
        {
            Wait.Begin("Loading Patient List...");
            _messenger.Send<ReadmitPatientListViewModel>(this);
            _messenger.Send<Messages.NavigationRequest<SubClasses.URI.PageURI>>(GetNavRequest_QUESTIONAIRRESHELL());

        }

        private static Messages.NavigationRequest<SubClasses.URI.PageURI> GetNavRequest_QUESTIONAIRRESHELL()
        {
            Messages.NavigationRequest<SubClasses.URI.PageURI> navRequest =
                new Messages.NavigationRequest<SubClasses.URI.PageURI>(
                    new SubClasses.URI.PageURI(Helpers.PageLinks.QUESTIONAIRRESHELL, System.UriKind.Relative));
            return navRequest;
        }
于 2011-06-06T18:42:59.723 回答