我正在列表视图中显示图像。当我点击的时候,我需要在同一个应用程序中全屏打开该图像。因此,当用户单击back按钮时,应该会返回到列表视图。我可以使用哪个控件或如何实现(全屏显示图像)。对于c#和UWA开发来说,这是相当新的。
谢谢
发布于 2016-10-14 14:04:29
当我单击时,我需要在同一应用程序中全屏打开该图像
根据您的需求,一种简单的方法是,您可以从ListView导航到第二个页面,并使用ImageControl在页面上全屏显示图像。导航代码如下:
private void Image_PointerPressed(object sender, PointerRoutedEventArgs e)
{
Image selectedimage = e.OriginalSource as Image;
Images select = (Images)selectedimage.DataContext;
Frame.Navigate(typeof(ShowImage),select);
}另一种方法是使用ContentDialog控件显示具有弹出视觉效果的图像。如果要全屏显示图像,则需要将ContentDialog的FullSizeDesired属性设置为true。ContentDialog代码如下:
<ContentDialog
...
FullSizeDesired ="True"
HorizontalAlignment="Stretch"
Canvas.ZIndex="1" MaxHeight="1920" MaxWidth="1440">
<Image x:Name="showimage" Source="{Binding ImageUrl}" Stretch="Fill" Margin="0"></Image>
</ContentDialog>,这样当用户单击back按钮时,它应该会返回到列表视图。
为此,您需要启用系统back button导航,并对其进行配置,使第二个页面可以返回到主页。App.xaml.cs中后退按钮的代码如下:
private void App_BackRequested(object sender,
Windows.UI.Core.BackRequestedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
return;
if (rootFrame.CanGoBack && e.Handled == false)
{
e.Handled = true;
rootFrame.GoBack();
}
}我测试过了,上面提供的两种方法都可以返回到ListView by back按钮。更多详细信息请参考完成的演示here,您可以下载以进行测试,看看它是否是您想要的。
此外,跟随universal application platform guide探索更多关于uwp开发的内容。
https://stackoverflow.com/questions/40026306
复制相似问题