图像边距行为
当我在运行时设置图像边距时,它的行为很奇怪,与我通过 xaml 代码设置它时不同。
我希望边距值为 (40, 16, 0, 0)。
当我在运行时添加它时,我的代码是这样的:
System.Windows.Controls.Image proba = new System.Windows.Controls.Image();
ImageSource imageSource = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");
proba.Source = imageSource;
proba.Width = 2245721 / 9525;
proba.Height = 2286004 / 9525;
proba.Margin = new Thickness(40, 16, 0, 0);
gridName.Children.Add(proba);
但是,当我在 xaml 中添加图像时,cs 中的代码是这样的:
image1.Source = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");
xaml 中的代码是这样的:
<Window x:Class="GetInfoFromPptxFile.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="720" Width="960">
<Grid Name="gridName">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="416,20,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<Image Height="150" HorizontalAlignment="Left" Margin="40,16,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
</Grid>
</Window>
当我运行程序时,image1 正是我想要的位置它是,而名为 proba 的图像则不是。当我给他们相同的保证金值时,为什么会出现这种情况?
When I set my image margin in run-time it acts strange, different then when I set it via xaml code.
I want the margin value to be (40, 16, 0, 0).
When I add it in run-time, my code is this:
System.Windows.Controls.Image proba = new System.Windows.Controls.Image();
ImageSource imageSource = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");
proba.Source = imageSource;
proba.Width = 2245721 / 9525;
proba.Height = 2286004 / 9525;
proba.Margin = new Thickness(40, 16, 0, 0);
gridName.Children.Add(proba);
But, when I add image in xaml, the code in cs is this:
image1.Source = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");
and the code in xaml is this:
<Window x:Class="GetInfoFromPptxFile.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="720" Width="960">
<Grid Name="gridName">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="416,20,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<Image Height="150" HorizontalAlignment="Left" Margin="40,16,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
</Grid>
</Window>
When I run my program, image1 is exactly where I want it to be, and the image named proba is not. Why is this when I give them the same margin values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为您没有在 C# 中设置水平和垂直对齐方式。
尝试添加:
看起来会一样。
That's because you're not setting the horizontal and vertical alignments in C#.
Try adding:
and it'll look the same.