在 WPF 中从视图过渡到视图 [英] Transitioning from View to View in WPF

查看:64
本文介绍了在 WPF 中从视图过渡到视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几周以来,我一直在研究 MVVM 和 WPF,因为我正在为另一个开发人员为其做后端的应用程序组合一个 UI.我没有大量的 GUI 经验,所以我只是在尝试解决问题.

I've been researching MVVM and WPF for a few weeks now, as I'm putting together a UI for an Application that another developer is doing the backend for. I don't have tons of GUI experience, so I'm just trying to figure it out as I go along.

我开始理解将后端代码与 UI 分开的概念,但我只能在网上找到简单的 MVVM 一个 Window 示例.

I'm starting to understand the concept of keeping the backend code separate from the UI, but I can only find simple, one Window examples of MVVM online.

我正在设计的应用程序是一个自助服务终端,它可以根据用户输入和扫描信息逐步浏览一系列屏幕.分离和设计这些过渡的好方法是什么?

The application I'm designing is a Kiosk that moves step-by-step through a series of screens based on user input and scans. What is a good way to separate and design these transitions?

例如,我有一个欢迎屏幕,等待用户扫描他们的 ID.一旦它获得他们的 ID,它就会显示一个新的窗口,或视图,或任何你想调用的东西,要求用户确认扫描的信息并按下继续按钮.

For example, I have a welcome screen that waits for the user to scan their ID. Once it gets their ID, it shows a new Window, or View, or whatever you want to call it, asking the user to confirm the scanned information and push the continue button.

然后它移动到一个新的屏幕,用户在那里进行选择等等,直到在几个屏幕"之后,结果被打印出来并为下一个用户重置.

Then it moves to a new screen where the user makes selections and so on until, and after a couple more "screens", the result is printed and it resets for the next user.

网络上有没有好的实现示例?

Are there any good implementation examples of this on the web?

应用程序是全屏的.我的第一直觉是将每个屏幕设计为一个单独的窗口,然后一个接一个地 Show() 它们,但这看起来很草率,我猜这不是最好的方法.

The application is full screen. My first instinct was to just design each screen as a separate window and Show() them one after the other, but this seems sloppy and I'm guessing it's not the best way.

我尝试的另一件事是让每个人都查看一个 UserControl 并将它们加载到一个主面板中,根据步骤一个接一个.再一次,不确定这是最好的方法.

Another thing I tried was to make each individual view a UserControl and load them in one main panel, one after the other based on the step. Once again, not sure this is the best method.

推荐答案

在您的 MainView 中添加一个内容控件,如下所示,

Add a Content Control in your MainView like below,

<ContentControl Content="{Binding CurrentView}"/>

为不同的视图创建DataTemplates,如下所示,

Create DataTemplates for your different Views like below,

<DataTemplate x:Key="Viewer"  DataType="{x:Type VM:TiffImageViewerViewModel}">//ViewModel Name
        <view:TiffViewer/>//View Name
</DataTemplate>

主视图模型

public object CurrentView { get; set; }

private TiffImageViewerViewModel _TiffImageViewerViewModel;
    public TiffImageViewerViewModel TiffImageViewerViewModel
    {
        get
        {
            return _TiffImageViewerViewModel;
        }
        set
        {
            _TiffImageViewerViewModel = value;
        }
    }

创建object 并将其分配给CurrentView.这个链接更加清晰

Create the object and assign it to CurrentView. This link gives more clarity

这篇关于在 WPF 中从视图过渡到视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆