C# 如何在Windows应用商店应用程序中通过goback命令传递参数
在NavigationHelper中使用Binding Goback命令时,我希望将一个参数传递到我访问的上一页 XAML中的后退按钮C# 如何在Windows应用商店应用程序中通过goback命令传递参数,c#,xaml,windows-store-apps,C#,Xaml,Windows Store Apps,在NavigationHelper中使用Binding Goback命令时,我希望将一个参数传递到我访问的上一页 XAML中的后退按钮 <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
<Button x:Name="backButton"
Margin="39,59,39,0"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"
IsEnabled="{Binding IsBackEnabled}"/>
然后取回它
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string myParam = e.Parameter.ToString();
}
您可以在
XAML
中使用CommandParameter
来执行此操作
<Button x:Name="backButton"
Margin="39,59,39,0"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
CommandParameter="This is my parameter"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"
IsEnabled="{Binding IsBackEnabled}"/>
这里有一个解决方案,尽管可能有更好的方法 C#代码隐藏 在使用GoBack命令的页面中,声明GoBack方法:
private void GoBack()
{
string myArg = "Hello";
this.Frame.Navigate(typeof(AnotherPage), myArg);
}
public MyPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
this.navigationHelper.GoBackCommand = new RelayCommand(GoBack);
}
然后在页面构造函数中,只需将GoBack命令设置为GoBack方法:
private void GoBack()
{
string myArg = "Hello";
this.Frame.Navigate(typeof(AnotherPage), myArg);
}
public MyPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
this.navigationHelper.GoBackCommand = new RelayCommand(GoBack);
}
明亮的那么我在哪里处理上一页的参数呢?看看这个