本文介绍了如何在Xamarin.Forms中将参数从一页传递到另一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过 MVVM模式将表单中的按钮按下到另一个表单时发送一个值.
I want to send a value when I press a button in a form to another form through the MVVM pattern.
这是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
,将我重定向到其他表单.
And this is my ModelView class
where I get redirected to another form.
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"?
The jump works. How can I send that "CommandParameter" to "Page2" ?
谢谢,德拉戈斯
推荐答案
最简单的方法是将值作为参数传递给Page2的构造函数.或者,您也可以在Page2上创建一个公共属性,并在创建属性后为其分配值.
The easiest approach would be to pass the value as a parameter to the constructor of Page2. Or you could create a public property on Page2 and assign the value to it after you create it.
await _navigation.PushAsync(new Page2(argument_goes_here)); // HERE
这篇关于如何在Xamarin.Forms中将参数从一页传递到另一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!