gpt4 book ai didi

Silverlight Windows Phone 7 - 使用硬件后退按钮后按钮单击事件丢失

转载 作者:行者123 更新时间:2023-12-04 06:30:25 26 4
gpt4 key购买 nike

在 Windows phone 7 Silverlight 项目中,当折叠包含按钮的面板,然后使用硬件后退按钮返回(再次将可见性设置为可见)时,FIRST 单击事件丢失。

这让我发疯了一段时间。

这是一种简单的重现方法,启动一个新的 Wp7 silverlight 应用程序,然后在 xaml 上添加两个带有按钮的内容面板。

    <Grid x:Name="ContentPanel" Grid.Row="1" Visibility="Visible">
<Button Content="Change Visibility" Click="ChangeButton_Click"/>
</Grid>
<Grid x:Name="ContentPanel2" Grid.Row="1" Visibility="Collapsed">
<Button Content="Back" Click="BackButton_Click"/>
</Grid>

后面的代码有两个按钮和硬件后退按钮的处理程序,可以简单地在两个面板之间切换可见性。
    public MainPage()
{
InitializeComponent();
BackKeyPress += new EventHandler<System.ComponentModel.CancelEventArgs>(MainPage_BackKeyPress);
}

void MainPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
if (ContentPanel2.Visibility == Visibility.Visible)
{
ContentPanel.Visibility = Visibility.Visible;
ContentPanel2.Visibility = Visibility.Collapsed;
e.Cancel = true;
}
}

private void ChangeButton_Click(object sender, RoutedEventArgs e)
{
ContentPanel.Visibility = Visibility.Collapsed;
ContentPanel2.Visibility = Visibility.Visible;
}

private void BackButton_Click(object sender, RoutedEventArgs e)
{
ContentPanel.Visibility = Visibility.Visible;
ContentPanel2.Visibility = Visibility.Collapsed;
}

现在奇怪的事情是:
  • 如果您使用屏幕上的后退按钮切换工作正常
  • 如果使用硬件后退按钮切换回来,那么之后的FIRST click事件就会丢失!

  • 这发生在模拟器和真实设备上。

    这是一个错误吗?或者我做错了什么?

    最佳答案

    有人叫 Fendors(谢谢!)在 app hub forums 上回答了我的问题.他没有找到它发生的原因,但找到了一个解决方法:

    "I didn't figure out fully what is happening when the hardware back button is clicked, but did find a workaround. I was initially thinking maybe there was some sort of focus issue and found that if you set the content panel from visible to collapsed to visible, it puts it into a good state"


    void MainPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) 
    {
    if (ContentPanel2.Visibility == Visibility.Visible)
    {
    ContentPanel2.Visibility = Visibility.Collapsed;
    ContentPanel.Visibility = Visibility.Visible;
    ContentPanel.Visibility = Visibility.Collapsed;
    ContentPanel.Visibility = Visibility.Visible;

    e.Cancel = true;
    }
    }

    关于Silverlight Windows Phone 7 - 使用硬件后退按钮后按钮单击事件丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5483239/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com