xaml - Windows 8 图像均匀填充居中

标签 xaml windows-8 windows-store-apps

我有一个小问题,我有一个组项目,我想提供一个背景图像,它应该缩放以保持正确的尺寸,但默认情况下它从左上角显示图像,我希望图像居中。

这是进一步解释我的问题的插图。 (灰色部分是剪掉的部分)

My problem

我有这个 XAML

<Image Source="/url/to/image.jpg" Stretch="UniformToFill"/>

最佳答案

我设法解决了我的问题,我使图像比放置它的容器大,并在中心垂直对齐。

<Grid HorizontalAlignment="Left" Width="250" Height="125">
    <Image Source="/url/to/image.jpg" Stretch="UniformToFill" Height="250" Margin="0" VerticalAlignment="Center"/>
</Grid>

图像的溢出是不可见的:)

关于xaml - Windows 8 图像均匀填充居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13535022/

相关文章:

visual-studio-2012 - 为 Windows 应用商店应用编写脚本创建程序包

windows-8 - WinRT-XAML 中是否有 WrapPanel(不是 WrapGrid)控件?

wpf - 为什么我的 xaml 只显示一个没有任何内容的普通窗口

xaml - 在 App.xaml 上添加基于样式在 App() { InitializeComponent(); }

通用 Windows 应用程序中的 JavaScript 引擎(C#、XAML)

c# - 尝试使用 sqlite-net 按 PrimaryKey 选择时,SQLite 没有结果

wpf - 适用于 XAML 的 Windows Metro 中的 DrawingBrush 在哪里

c# - WPF 事件触发器

c# - Metro 获取 StorageFile 的 base64 字符串

javascript - WinJS.Namespace.define 不工作