c# - 如何在 Xamarin.Forms 中将参数从一个页面传递到另一个页面?

标签 c# xaml mvvm xamarin xamarin.forms

我想通过 MVVM 模式 在一个表单中按下按钮时向另一个表单发送一个值。

这是 XAML 文件

 <Button x:Name="myButton"
            Text="RandomButton"
            TextColor="#000000"
            BackgroundColor="{x:Static local:FrontEndConstants.ButtonBackground}"
            Grid.Row="2" Grid.Column="0"
            Grid.ColumnSpan="3"
            Command="{Binding NewPage}"
            CommandParameter="100">     
</Button>

这是我的 ModelView 类,我在这里被重定向到另一个表单。

class JumpMVVM :INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private INavigation _navigation;

        public ICommand NewPage
        {
            get
            {
                return new Command(async () =>
                { 
                    await _navigation.PushAsync(new Page2()); // HERE
                });
            }
        }

        public JumpMVVM() { }

        public JumpMVVM(INavigation navigation)
        {                
            _navigation = navigation;                
        }

跳跃有效。如何将“CommandParameter”发送到“Page2”?

谢谢, 德拉戈斯

最佳答案

最简单的方法是将值作为参数传递给 Page2 的构造函数。或者,您可以在 Page2 上创建一个公共(public)属性,并在创建后为其分配值。

await _navigation.PushAsync(new Page2(argument_goes_here)); // HERE

关于c# - 如何在 Xamarin.Forms 中将参数从一个页面传递到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28278506/

相关文章:

c# - 将 JSON 对象传递给 MVC

c# - 使用 GridSplitter 隐藏列并自动调整列大小

c# - 反复按下按钮时,ColorAnimation 停留在颜色上

wpf - 如何以 MVVM 模式加载 wpf 用户控件

c# - 为嵌套属性实现 INotifyPropertyChanged

javascript - Knockout.js 的 View 模型声明。有两种方法

c# - 如何将 POST 请求正文中的有效 XML 提交到使用 XML 的 ASP.NET Core Web API?

c# - 是否可以在 C# 和非托管 C++ 之间共享枚举声明?

c# - 如何在 WPF 中的 Devexpress 工具上使用 Grid inside Grid(嵌套网格)

c# - WPF 验证取决于必填/非必填字段