我想创建一个窗口,它将显示一个在另一个之下的图片列表。我创建了一个包含视框控制和图像在它:WPF Viewbox和图像大小
<UserControl x:Class="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Viewbox Name="viewbox">
<Image Height="10" Name="image" Width="10" HorizontalAlignment="Left" VerticalAlignment="Top" />
</Viewbox>
</Grid>
</UserControl>
public BitmapImage Image
{
get { return image.Source as BitmapImage; }
set { changeImage(value); }
}
public SingleIllustrationViewer()
{
InitializeComponent();
}
private void changeImage(BitmapImage img)
{
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
float dpiX = graphics.DpiX/96;
this.image.BeginInit();
this.image.Source = img;
this.image.EndInit();
this.image.Width = img.PixelWidth/img.DpiX * dpiX;
}
,我把图片上的窗口是这样的:
double margin = 0;
for (int i = 0; i < illustrations.Count; i++)
{
String path = illustrations[i].printVersions.Last<String>();
BitmapImage bmp = new BitmapImage(new Uri(path));
Controls.SingleIllustrationViewer iv = new Controls.SingleIllustrationViewer();
iv.VerticalAlignment = System.Windows.VerticalAlignment.Top;
iv.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
iv.Margin = new Thickness(50, margin, 0, 0);
iv.Image = bmp;
grid.Children.Add(iv);
margin += iv.Image.Height + 20;
}
因此,举例来说,我已经放在拍摄3张照片(所有3个相同的宽度)就像这样,并且得到了这样一个有趣的行为:第一个是好的,第二个是小的,第三个小于一秒。这里是屏幕截图:
也许有人可以告诉我为什么是这样,以及如何解决这个问题,以同样的宽度看到所有这些图片?
谢谢!
的问候,托马斯
你尝试视框的Stretch属性:http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.stretch(v=vs.110).aspx – bit 2014-09-25 08:33:18
您增加了每幅图片的边距:'margin + = iv.Image.Height + 20;' – Bolu 2014-09-25 11:37:09