0
我正在用图像填充ViewBox,尽管我似乎无法将其置于图像中心。我试着将ViewBox Fill设置为UniformToFill,将图像垂直和水平居中等,没有任何东西可以工作。如何在ViewBox中居中图像
XAML
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Viewbox MaxWidth="500" MaxHeight="500" Name="vb1">
<Image x:Name="MyImage"/>
</Viewbox>
</StackPanel>
XAML.CS
BitmapImage bitimg = new BitmapImage(new Uri("/MyNewLink.jpg", UriKind.Relative));
MyImage.Source = bitimg as ImageSource;
我不能说'WindowsPhone',但在WPF中,你的使用过的代码绝对没有错。无论我调整“窗口”的大小,我都无法让图像以*为中心。你的形象有多大? – Sheridan
为什么你在Code后面设置图像源? – Sajeetharan
@Sheridan该图像相当大,它来自PhotoChooserTask,因此尺寸取决于用户的设备相机设置。 – Matthew