全屏显示图像

时间:2014-02-17 12:27:52

标签: c# wpf windows-phone-8 windows-phone fullscreen

我正在使用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"/>

现在我有一个名为Tap="Image_tap"的活动,当我点击图像时我想在全屏显示同一图像而顶部和底部没有任何条形图,如何实现这一点?

2 个答案:

答案 0 :(得分:7)

另一种方法是在不在页面之间传递图像细节的情况下显示弹出窗口:

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; 
}

(选择最适合您需求的Strech值)。 但是,使用此方法,您必须在HandleTapImage方法中手动隐藏ApplicationBar和SystemTray(如果存在)。您还必须注意隐藏弹出窗口并再次显示条形图。

答案 1 :(得分:5)

底栏为ApplicationBar,顶栏为SystemTray。如果您创建的新页面没有ApplicationBarSystemTray.IsVisible为false,那么您将拥有一个全屏页面。现在,不要在根目录中放置Grid,只需放置一个Image,您就可以将该页面用作全屏查看器。

<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>

在主页中点按图片:

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));
}

在全屏页面中:

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