1
在我的WP 7.1 App中,我有两个名为“PAGE 1”,“PAGE 2”的页面,并有两个按钮位于第1页的“按钮1”和“按钮2“在页2.但是我点击按钮1从页1它自动点击按钮2在第2页..是否有可能??请尽快帮助我..如何将按钮点击事件从一个页面传递到另一个页面按钮
在我的WP 7.1 App中,我有两个名为“PAGE 1”,“PAGE 2”的页面,并有两个按钮位于第1页的“按钮1”和“按钮2“在页2.但是我点击按钮1从页1它自动点击按钮2在第2页..是否有可能??请尽快帮助我..如何将按钮点击事件从一个页面传递到另一个页面按钮
有点不清楚你的情况是什么 - 所以我打算写答案的情况下,我可以想像:
如果两页都在同样的观点(即,两个PanoramaItem
s每Panorama
),两个按钮都可以从代码隐藏的(如果你”不要使用Command
s - 就是这样)然后在事件处理程序中执行类似操作:
private void Button1_Click(object sender, EventArgs e)
{
// Do action for Button1_Click
// ...
// Then call the event handler for Button2
Button2_Click(sender, e);
}
如果存在两个不同的页面(即,两个不同的XAML),您将不得不通过NavigationService
发送某种参数。在Button1View.xaml
:
// a flag remembering if the button has been clicked
private bool hasButton1BeenClicked = false;
// The event handler for Button1
private void Button1_Click(object sender, EventArgs e)
{
// Do action for Button1_Click
// ...
// Then set a flag that says it has been clicked
}
// This method puts on the flag if the button was clicked
private string PrepareAddressToButtonView2(string uriToButtonView2)
{
if(hasButton1BeenClicked)
{
uriToButtonView2 = uriToButtonView2 + "?button1clicked=true";
}
return uriToButtonView2;
}
当你在你的第二个观点后,你必须手动触发第二个按钮的事件处理程序 - 但只有在按钮1被点击的一个视图。在Button2View.xaml
:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if(NavigationContext.QueryString.ContainsKey("button1clicked"))
{
Button2_Click(null, null);
}
}
另一种方式来解决,这将是拯救Button1的状态(静态字段的地方),然后选中这个时候第2页导航到。
希望这对你有所帮助!