简体   繁体   English

全屏显示图像

[英]Show image in Full screen

I am working on Windows Phone 8 app and have a Image view like this in XAML: 我正在使用Windows Phone 8 app并且在XAML中具有这样的图像视图:

<Image Name="Image"
       Grid.Row="0"
       Visibility="Collapsed"
       Width="Auto"
       Height="Auto"
       Tap="Image_tap"
       HorizontalAlignment="Center"
       VerticalAlignment="Center"
       Margin="1,1,1,1"/>

Now i have this event called Tap="Image_tap" , when i tap on the image i want to show the same image in full screen without any bar on top and bottom, how to acheive this ? 现在我有一个名为Tap="Image_tap"事件,当我点击图像时,我想以全屏显示同一图像,而顶部和底部没有任何条形,该如何实现?

An alternative approach, without passing the image details between pages, is to display a Popup: 在页面之间不传递图像详细信息的另一种方法是显示弹出窗口:

private void HandleTapImage(object sender, GestureEventArgs e)
{
    var myPopup = new Popup
    {
        Child = new Image
        {
            Source = ((Image) sender).Source,
            Stretch = Stretch.UniformToFill,
            Height = Application.Current.Host.Content.ActualHeight,
            Width = Application.Current.Host.Content.ActualWidth
        }
    };
    myPopup.IsOpen = true; 
}

(Select Strech value best suited for your needs). (选择最适合您需求的Strech值)。 With this approach however you have to manually hide ApplicationBar and SystemTray, if present, in the HandleTapImage method. 但是,使用这种方法必须在HandleTapImage方法中手动隐藏ApplicationBar和SystemTray(如果存在)。 You also have to take care of hiding the Popup and showing the bars again. 您还必须注意隐藏弹出窗口并再次显示条。

Bottom bar is ApplicationBar and top bar is SystemTray . 底部栏是ApplicationBar ,顶部栏是SystemTray If you create a new page without the ApplicationBar and with SystemTray.IsVisible to false, you have a fullscreen page. 如果创建不带ApplicationBar且带SystemTray.IsVisible的新页面, SystemTray.IsVisible false,您将拥有一个全屏页面。 Now, instead of having a Grid at the root, place just one Image and you can use that page as a fullscreen viewer. 现在,只需在其中放置一个Image ,而不是在Grid的根部,您就可以将该页面用作全屏查看器。

<phone:PhoneApplicationPage
    x:Class="SimpleApp.FullScreenPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="False">

    <Image Name="myImage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
         Stretch="Uniform"/>

</phone:PhoneApplicationPage>

In MainPage where you tap image: 在您点击图像的MainPage中:

private void myImg_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
   string context = ((sender as Image).Source as BitmapImage).UriSource.ToString();
   NavigationService.Navigate(new Uri(String.Concat("/Page1.xaml?context=", context), UriKind.RelativeOrAbsolute));
}

In Fullscreenpage: 在全屏页面中:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
   string context = this.NavigationContext.QueryString["context"];
   myImage.Source = new BitmapImage(new Uri(context, UriKind.RelativeOrAbsolute));
   base.OnNavigatedTo(e);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM