![](/img/trans.png)
[英]Unable to navigate to another page on button click in windows phone 8.1
[英]Navigate to Button Click Event in Lens Application for Windows Phone 8
在Windows Phone的默認相機應用程序中按我的應用程序的“鏡頭”平鋪圖標后,我想導航到我的應用程序。 盡管我正在使用CameraCaptureTask拍攝照片,然后將其保存並顯示在MainPage中,但我仍在工作。 我在單擊事件上調用CameraCaptureTask,所以我的問題是,當我在鏡頭選擇器中選擇“應用程序磁貼”時,如何訪問此單擊事件?
App.xaml.cs
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
//RootFrame = new PhoneApplicationFrame();
RootFrame = new TransitionFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Assign the lens example URI-mapper class to the application frame.
RootFrame.UriMapper = new LensUriMapper();
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Handle reset requests for clearing the backstack
RootFrame.Navigated += CheckForResetNavigation;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
LensUriMapper.cs
class LensUriMapper : UriMapperBase
{
private string tempUri;
public override Uri MapUri(Uri uri)
{
tempUri = uri.ToString();
// Look for a URI from the lens picker.
if (tempUri.Contains("ViewfinderLaunch"))
{
// Launch as a lens, launch viewfinder screen.
//return new Uri("/Views/MainPage.xaml", UriKind.Relative);
return new Uri("/Views/MainPage.xaml?Viewfinder=1", UriKind.Relative);
}
}
// Otherwise perform normal launch.
return uri;
}
}
MainPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey("Viewfinder"))
{
newButton_Click(null, null);
}
}
void newButton_Click(object sender, EventArgs e)
{
_cameraTask.Show();
}
另外,如何按MSDN的鏡頭應用指南中所述的后退鍵直接導航回默認的相機應用程序?
您可以向ViewfinderLaunch uri添加參數:
return new Uri("/Views/MainPage.xaml?Viewfinder=1", UriKind.Relative);
接下來,您必須覆蓋MainPage的“ OnNavigatedTo”方法,以檢查是否設置了Viewfinder參數:
if (NavigationContext.QueryString.ContainsKey("Viewfinder"))
{
newButton_Click(null, null);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.