1

Silverlight で 4 ~ 5 個のビューを持つ単純なアプリケーションを構築しています。MVVM Light ツールキットに出会いましたが、それは私のニーズに合っていると思います。

バックグラウンド

アプリケーションには、典型的なリストと詳細を表示するビューがあります

  • メーカー
  • 製品

左側のナビゲーション、ヘッダー、フッター (ユーザー コントロール) など。

設計時に作成されたユーザー コントロールを含むメイン ページを作成することを考えています。

問題

左側のナビゲーション コントロールからリンクを選択すると、中央パネルが別のビュー (メーカー、製品など) で更新されます。

Messenger は、ライト ツールキットで異なる VM 間で通信するためのオプションであることを理解しています。

質問

MVVM ライト ツールキットを使用してアプリを設計するにはどうすればよいですか。中央ペインは、実行時に別のビューでロードする必要があります。

特に、アプリケーションのナビゲーション部分を実装する際のヘルプを検討しています。

ありがとうございました。

4

1 に答える 1

1

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;
        }
于 2011-06-06T18:42:59.723 に答える