gpt4 book ai didi

mvvm - 如何使用多 ContentView 制作多步骤注册页面?

转载 作者:行者123 更新时间:2023-12-03 10:32:15 26 4
gpt4 key购买 nike

在我正在开发的应用程序中,有一个多步骤注册,4 个步骤:
为了完成它,我想有一个页面来托管注册步骤的内容 View ,当它通过验证要求时,我将其删除并注入(inject)下一个内容 View 。
这是一个简化我的需求的例子:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamApp"
x:Class="XamApp.MainPage">
<local:Register1/>
</ContentPage>

Register1 看起来像这样:
    <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamApp"
x:Class="XamApp.Register1">
<ContentView.Resources>
<ResourceDictionary>
<local:IntToBoolConverter x:Key="intToBool"/>
</ResourceDictionary>
</ContentView.Resources>
<ContentView.Content>
<StackLayout>
<Label Text="Page 1" FontSize="Large"/>
<Entry x:Name="txtName" Placeholder="Name"/>
<Button Text="Next" IsEnabled="{Binding Source={x:Reference txtName},
Path=Text.Length,
Converter={StaticResource intToBool}}"
Clicked="Button_Clicked"/>
</StackLayout>
</ContentView.Content>
</ContentView>

有两个问题:

1-我不知道如何处理步骤之间的数据( View 模型),通过所有步骤只有一个对象 (我应该使用 DI 吗?如果是,那么如何在 MVVMLight 中使用?)

2- 如何以 MVVM 方式将内容 View 动态注入(inject)主注册页面?

最佳答案

我想出的解决方案是创建一个界面:

    public interface INavigate
{
INavigate Next();
INavigate Previous();
}

所有 ContentView s 继承自,例如第二个 ContentView执行:
    public INavigate Next()
=> new View3();

public INavigate Previous()
=> new View1();

容器页面的 Content属性绑定(bind)到 View 模型的属性 CurrentView类型 INavigate ,
下一个按钮的命令执行这个:
CurrentView = CurrentView.Next();

这是上一个按钮:
CurrentView = CurrentView.Previous();

关于mvvm - 如何使用多 ContentView 制作多步骤注册页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53903056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com