微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何使用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 举报,一经查实,本站将立刻删除。