【问题标题】:Windows Phone 8 fullscreen pageWindows Phone 8 全屏页面
【发布时间】:2013-03-13 13:27:35
【问题描述】:

我在 Windows Phone 8 的 XAML 中定义了以下页面

<phone:PhoneApplicationPage x:Class="MangaRack.View.Phone.View.ChapterView"
    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"
    shell:SystemTray.IsVisible="False">
    <Grid Background="White">
        <Button BorderThickness="0" Name="ImageButton" Padding="0">
            <Image Name="Image" />
        </Button>
    </Grid>
</phone:PhoneApplicationPage>

Grid 定义了一个应用于整个屏幕的白色背景,但是 Grid 的内容不在窗口边缘附近,在 Image 和窗口边缘之间有一个可观察的边距/填充。 如何确保图像直接靠在窗口边缘

【问题讨论】:

    标签: .net windows-phone-7 xaml windows-phone-8 winrt-xaml


    【解决方案1】:

    尝试设置你的图片Stretch属性:

    <Image Name="Image" Stretch="UniformToFill"/>
    

    有关详细信息,请参阅MSDN pages regarding image stretching

    此外,您的按钮会在您的图像周围添加一些“填充”。为避免这种情况,您将不得不更改其模板。我会将模板替换为仅呈现内容的模板:

         <Button>
             <Button.Template>
                <ControlTemplate TargetType="Button">
                    <StackPanel x:Name="stackPanel" Orientation="Horizontal">
                        <ContentPresenter VerticalAlignment="Bottom"/>
                    </StackPanel>
                </ControlTemplate>
             </Button.Template>
            <Image Name="Image" Stretch="UniformToFill"/>
          </Button>
    

    不过,如果您完全移除“chrome”按钮,您也可以直接使用图像并处理图像上的点击/点击事件。

    【讨论】:

    • 这会将图像拉伸到按钮容器。它仍然没有填满整个屏幕,所以我怀疑问题出在按钮、网格或页面本身上。
    • 我会考虑完全删除按钮。谢谢你的模板方向,我从来没有想过这个。美丽:)
    【解决方案2】:

    你可以把你的图片放在一个网格里,这样它就会全屏显示,这里是 C# 编码

        System.Windows.Media.ImageBrush myBrush = new System.Windows.Media.ImageBrush();
            Image image = new Image();
            image.ImageFailed += (s, i) => MessageBox.Show("Failed to load: " + i.ErrorException.Message);
            image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"/Assets/bg/bg5.jpg/", UriKind.RelativeOrAbsolute));
            myBrush.ImageSource = image.Source;
            grid1.Background = myBrush;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      相关资源
      最近更新 更多