簡體   English   中英

Windows 10 UWA(圖像顯示)

[英]Windows 10 UWA (Image display)

我在列表視圖中顯示圖像。 當我單擊時,我需要在同一應用程序中全屏打開該圖像。 因此,當用戶單擊“后退”按鈕時,應將其帶回到列表視圖。 哪個控件或我該怎么做(全屏顯示圖像)。 對C#和UWA開發來說是相當新的。

謝謝

當我單擊時,我需要在同一應用程序中全屏打開該圖像

根據您的要求,一種簡單的方法是,您可以從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>

因此,當用戶單擊“后退”按鈕時,應將其帶回到列表視圖。

為此,您需要啟用系統后退按鈕導航並將其配置為使第二頁可以返回到主頁。 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。 更多詳細信息,請參考此處完整的演示,您可以下載進行測試以查看它是否是您想要的。

此外,遵循通用應用程序平台指南以探索有關uwp開發的更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM