当 WP7 页面更改为横向时更改背景位置
我正在开发一个 Windows Phone 7 项目,其主页上有全景图和多个简单页面。我的所有页面都以这种方式设置背景:
<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 像素。
当页面以纵向显示时,图片会正确水平居中,并且图片高度与页面高度相对应。这很好。
当页面以横向显示时,图片宽度对应于页面宽度,但图片垂直居中。
我希望我的背景图片位于页面的“顶部”。
网格的背景属性是一个画笔,没有有趣的选项。我不想为此创建两张图片。应该有一个明显的解决方案。这是我想要的结果:
I am working on a Windows Phone 7 project with a panorama on the MainPage and multiple simple pages. All my pages have a background set this way:
<local:PhoneApplicationPage>
<Grid Background="{StaticResource PageBackground}">
content here
</Grid>
</local:PhoneApplicationPage>
PageBackground is an application resource set in default.xaml and light.xaml this way:
<ImageBrush x:Key="PanoramaBackground" ImageSource="/Resources/PanoramaBackground01Dark.jpg" Stretch="None" />
<ImageBrush x:Key="PageBackground" ImageSource="/Resources/PageBackground01Dark.jpg" Stretch="None" />
The PageBackground01Dark.jpg picture is of size 800x800 px.
When a page is displayed in the Portrait orientation, the picture is centered correctly horizontaly and the picture height corresponds to the page height. This is fine.
When a page is displayed in the Landscape orientation, the picture width corresponds to the page width but the picture is then centered vertically.
I would like my background picture to be "topped" in the page.
The Background property of a Grid is a brush with no interesting options. I would like not to create 2 pictures for this. There should be an obvious solution. Here is the result I would like to have:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,解决办法很简单。 Background 属性的类型为 Brush,但它实际上是 ImageBrush。所以解决办法是:
Oh, the solution is simple. The Background property is of type Brush but it's in fact an ImageBrush. So the solution is: