C# 全屏显示图像
我正在使用Windows Phone 8应用程序,在XAML中有如下图像视图:C# 全屏显示图像,c#,wpf,windows-phone-8,windows-phone,fullscreen,C#,Wpf,Windows Phone 8,Windows Phone,Fullscreen,我正在使用Windows Phone 8应用程序,在XAML中有如下图像视图: <Image Name="Image" Grid.Row="0" Visibility="Collapsed" Width="Auto" Height="Auto" Tap="Image_tap" HorizontalAlignment="Center" VerticalAlignment="Center"
<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\u Tap的事件,当我点击图像时,我想全屏显示相同的图像,顶部和底部没有任何栏,如何实现这一点?底部栏是ApplicationBar,顶部栏是SystemTray。如果在不使用ApplicationBar且SystemTray.IsVisible为false的情况下创建新页面,则会显示全屏页面。现在,不需要在根目录中设置网格,只需放置一个图像,您就可以将该页面用作全屏查看器
<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>
在全屏页面中:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string context = this.NavigationContext.QueryString["context"];
myImage.Source = new BitmapImage(new Uri(context, UriKind.RelativeOrAbsolute));
base.OnNavigatedTo(e);
}
另一种不在页面之间传递图像详细信息的方法是显示弹出窗口:
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(如果存在)。您还必须注意隐藏弹出窗口并再次显示栏。您是否可以仅在上下文中传递图像的情况下导航到special FullScreen.xaml?或者有两个网格,一个有图像,另一个有用户界面,然后你可以改变它们的可见性。@Romasz,你能给我举个例子吗?什么。你知道如何在导航时传递上下文吗?@Romasz好的,我会等待,不,我是Windows phone 8应用程序开发新手,所以不知道,但我这里有这个链接,如果你能告诉我XAML页面是什么样子的话?@ToniPetrina+1,我想没有必要传递两个相同的答案;-我添加了一点。伙计们,我发现这个位图图像找不到。。。我需要添加哪个软件包?按Ctrl+。添加适当的namespace@Goofy使用System.Windows.Media.Imaging;我知道这瓶汽水找不到了?什么是程序集引用名称?+1很好的解决方案。我只添加了括号和有关在需要时隐藏页面内容的信息。System.Windows.Controls.Primitives我没有时间尝试此方法,但如果用户按Back键会发生什么情况?@ToniPetrina此方法未满。必须按下后退按钮才能关闭弹出窗口。此示例还缺少关闭弹出窗口时的事件,您应该在该窗口中更改元素的可见性。
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;
}