MVVM Light Toolkit 设计方法(导航和视图加载)

发布于 2024-11-14 10:59:52 字数 485 浏览 8 评论 0原文

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

背景

应用程序将具有包含典型列表和详细信息显示

  • 制造商
  • 产品

等的视图,以及左侧导航、页眉和页脚(用户控件)。

我正在考虑有一个主页,其中包含在设计时创建的用户控件。

问题

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

我知道 Messenger 是在不同虚拟机之间进行通信的一个选项工具包。

问题

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

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

谢谢。

I am building a simple application with 4-5 views in Silverlight. I came across MVVM Light toolkit and I think it suits my need.

Background

Application will have views with typical list and details display

  • Manufacturer
  • Product

and so on with left navigation, header and footer (User controls).

I am thinking of having a main page with user controls created at design time.

Problem

On selection of links from left navigation control, the central panel should be updated with a different view (like Manufacturer, product and so on)

I understand that Messenger is an option to communicate between different VMs in light toolkit.

Question

How can I design my app with MVVM light toolkit. Central pane need to be loaded with a different view at runtime.

I am particularly looking at help in implementing the navigation portion of the application.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2024-11-21 10:59:52

我必须以非 mvvm 方式实现基本的 nagivigtion。我的主视图的构造函数上有一个消息侦听器,用于侦听页面导航消息(自定义消息了解它、喜欢它、使用它),然后它将导航框架的内容源设置为在信息。我使用字符串常量设置了所有页面和子页面导航设置的 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";
    }

虚拟机中实际调用:

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;
        }

I had to implement basic nagivigtion in an NON mvvm way. I have a message listener sitting on the constructor of my main view that listens for a page navigation message(custom message learn it, love it,use it)then it sets the content source of the nav frame to the url that is sent in the message. I have the URLs for all my page and subpage navigation setup using string constants.

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";
    }

Actual Calling in 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;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文