【问题标题】:Change background position when WP7 Page changes to Landscape当 WP7 页面更改为横向时更改背景位置
【发布时间】:2011-03-29 01:15:44
【问题描述】:

我正在开发一个 Windows Phone 7 项目,该项目在 MainPage 上有一个全景图和多个简单页面。我所有的页面都有这样的背景设置:

<local:PhoneApplicationPage>
    <Grid Background="{StaticResource PageBackground}">
        content here
    </Grid>
</local:PhoneApplicationPage>

PageBackground 是在 default.xaml 和 light.xaml 中这样设置的应用程序资源:

<ImageBrush x:Key="PanoramaBackground" ImageSource="/Resources/PanoramaBackground01Dark.jpg" Stretch="None" />
<ImageBrush x:Key="PageBackground" ImageSource="/Resources/PageBackground01Dark.jpg" Stretch="None" />

PageBackground01Dark.jpg 图片大小为 800x800 像素。

当页面以纵向显示时,图片水平居中正确,图片高度与页面高度相对应。这很好。

当页面以横向显示时,图片宽度与页面宽度相对应,但图片然后垂直居中

我希望我的背景图片在页面中“置顶”。

Grid 的 Background 属性是一个没有有趣选项的画笔。我不想为此创建 2 张图片。应该有一个明显的解决方案。这是我想要的结果:

【问题讨论】:

    标签: xaml windows-phone-7


    【解决方案1】:

    哦,解决方法很简单。 Background 属性是 Brush 类型,但它实际上是 ImageBrush。所以解决办法是:

    <ImageBrush x:Key="PageBackground" 
                ImageSource="/Resources/PageBackground01Dark.jpg"
                AlignmentY="0" />
    

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多