一个PhotoChooserTask后应用程序任务栏图标按钮单击事件不解雇 [英] ApplicationBar icon button click event not fired after a PhotoChooserTask
问题描述
我不能得到ApplicationBarIconButton的点击事件在一定条件下火
I can't get the ApplicationBarIconButton's click event to fire under certain conditions.
我试图简化再现它所需的步骤:
I tried to simplify the steps required to reproduce it:
1)创建一个新的Windows Phone应用程序
1) Create a new Windows Phone Application
2)添加新的页面(的Page1.xaml)
2) Add a new Page (Page1.xaml)
3)添加在MainPage.xaml中一个简单的按钮启动一个PhotoChooserTask并导航到Completed事件的Page1.xaml
3) Add a simple button on MainPage.xaml launching a PhotoChooserTask and navigate to Page1.xaml on the Completed event
public partial class MainPage : PhoneApplicationPage
{
PhotoChooserTask photo;
public MainPage()
{
InitializeComponent();
photo = new PhotoChooserTask();
photo.Completed += OnCameraCaptureTaskCompleted;
}
void OnCameraCaptureTaskCompleted(object sender, PhotoResult args)
{
this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
photo.Show();
}
}
6)取消注释的Page1.xaml的应用程序任务栏部分,其中一个按钮的Click事件设置为一个新的事件处理程序
6) Uncomment the ApplicationBar section of Page1.xaml and set the click event of one of the buttons to a new event handler
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Won't work" Click="ApplicationBarIconButton_Click" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
MessageBox.Show("This messagebox won't show!");
}
启动它
Launch it
点击按钮,选择一张图片=>您将被重定向到的Page1.xaml
Click on the button to select a picture => you are redirected to Page1.xaml
点击ApplicationBarIconButton按钮:该事件不会触发
Click on the ApplicationBarIconButton button : the event isn't fired!
我错过了什么,或这是一个错误吗?
Did I miss something or that's a bug?
推荐答案
在张贴的问题后, WP7的官方论坛(这里是链接到的问题),我有一个答复,告诉这是一个已知的问题。
After posting that question on the WP7 official forum (here is the link to the question), I had a response telling that it's a known issue.
下面是似乎是官方的解决方法:
Here is what seems to be the "official" workaround:
void OnCameraCaptureTaskCompleted(object sender, PhotoResult args)
{
//Delay navigation until the first navigated event
NavigationService.Navigated += new NavigatedEventHandler(navigateCompleted);
}
void navigateCompleted(object sender, EventArgs e)
{
//Do the delayed navigation from the main page
this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
NavigationService.Navigated -= new NavigatedEventHandler(navigateCompleted);
}
(你需要添加使用系统.Windows.Navigation;
)
马特的变通办法太多,但我更喜欢使用NavigatedEventHandler比Dispatcher.BeginInvoke解决方案
Matt's workaround works too but I prefer using the NavigatedEventHandler than the Dispatcher.BeginInvoke solution.
这篇关于一个PhotoChooserTask后应用程序任务栏图标按钮单击事件不解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!