【发布时间】:2014-09-09 12:08:53
【问题描述】:
嗨,当我尝试使用 Label 作为容器将图像放到画布上时,我突然得到了 TOP + 4 Left + 4。我确实将图像发送到 = 0 left = 0 并将其放在顶部 = 4 left = 4); 请帮忙。谢谢
XAML:
<Grid >
<Canvas Name="TWCanvas" Margin="0,0,0,0" Height="1000" Width="1200"/>
</Grid>
代码:
Public void PutImg(string path)
{
Image img = new Image();
img.Width = 100;
img.Height = 100;
img.Source = new BitmapImage(new Uri(path, UriKind.Relative));
img.Stretch = Stretch.Fill;
Label lbl = new Label();
lbl.Content = img;
lbl.Margin = new Thickness(0, 0, 0, 0);
Canvas.SetLeft(lbl, 0);
Canvas.SetTop(lbl, 0);
TWCanvas.Children.Add(lbl);
}
【问题讨论】:
-
尝试使用 snoop 实用程序查看导致边距/填充问题的原因
-
@Krishna 您是否看到已经有一个答案可以解释观察到的行为?
-
@Clemens 我看到了,但请不要误解我。我只是建议使用 snoop,因为该工具可以帮助我解决此类问题,而不是为他们解决问题。如果你愿意,我很乐意删除我的评论:)
标签: c# wpf wpf-controls margin