wpf 全屏显示图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21829125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show image in Full screen
提问by Goofy
I am working on Windows Phone 8 appand 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",当我点击图像时,我想以全屏显示相同的图像,顶部和底部没有任何栏,如何实现?
回答by lisp
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).
With this approach however you have to manually hide ApplicationBar and SystemTray, if present, in the HandleTapImagemethod. You also have to take care of hiding the Popup and showing the bars again.
(选择最适合您需求的 Strech 值)。但是,使用这种方法,您必须在方法中手动隐藏 ApplicationBar 和 SystemTray(如果存在)HandleTapImage。您还必须注意隐藏弹出窗口并再次显示栏。
回答by Toni Petrina
Bottom bar is ApplicationBarand top bar is SystemTray. If you create a new page without the ApplicationBarand with SystemTray.IsVisibleto false, you have a fullscreen page. Now, instead of having a Gridat the root, place just one Imageand you can use that page as a fullscreen viewer.
底栏是ApplicationBar,顶栏是SystemTray。如果您创建一个没有ApplicationBar和的新页面SystemTray.IsVisible,则为假,您将拥有一个全屏页面。现在,不再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>
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);
}

