如何使用if条件将用户重定向到页面,以验证他在表单中引入的值?

问题描述

该应用程序具有一个注册页面”,当用户注册时,系统识别其配置文件类型以重定向其特定页面非常重要。 有两个用户配置文件和两个菜单。 我打算做的是以下操作:当拥有“ CodPerfil = 1”的用户单击回车按钮时,系统将定向到“ MenuMoradores”页面。 当“ CodPerfil = 2”时,系统将定向到“ MenuRecolhedores”页面。 应用程序从Web API获取值,并且'CodPerfil'值与在选择器'SelectedPerfil'中选择的值相对应。

这是viewmodel 我尝试了一种称为“ Validation()”的方法来完成这项工作,但是它不起作用。

//This property is of type 'Int' which is linked to the item selected 
in the picker that needs to be validated to direct to the pages. This property only have two values: 'CodPerfil=1','Titulo=Morador' that is binded in the picker and 'CodPerfil=2','Titulo=Recolhedor'.

public int CodPerfil
        {
            get
            {
                return _codperfil;
            }
            set
            {
                _codperfil = value;
                OnPropertyChanged();
            }
        }

public ICommand RegistarCommand
        {
            get
            {
                return new Command(async () =>
                {
                    var usuario = new UsuarioModel
                    {
                        Nome = Nome,Senha = Senha,Telefone = Telefone,CodPerfil = SelectedPerfil.CodPerfil
                    };
                    await _apiServices.RegistoUsuarioAsync(usuario);
                    if (usuario.CodPerfil == 1)
                    {
                        await Navigation.PushModalAsync(new MenuMorador());
                    }
                    else if (usuario.CodPerfil == 2)
                    {
                        await Navigation.PushModalAsync(new MenuRecolhedor());
                    }
                    else
                    {
                        //
                    }
                });

            } 
        }
... 
//I hid the code for the other properties and the selected item

RegisterPage.xaml 我只输入了最相关的代码


            <Picker x:Name="PerfilPicker" Title="Selecione o seu Perfil" FontSize="Large" HorizontalOptions="Center"
                    ItemsSource="{Binding Perfis}" 
                    ItemdisplayBinding="{Binding Titulo}" 
                    SelectedItem="{Binding SelectedPerfil}" />
                    Command="{Binding RegistarCommand}"/>

任何帮助将不胜感激。谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)