首页 > 解决方案 > 如何在没有 SetLeft 的情况下以编程方式更改图像位置?

问题描述

我以前搜索过,我认为Canvas.SetLeft(image, double)这将是答案,但它没有做任何事情

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Users\alu\Desktop\caballos_jpg\serie_2\02.jpg", UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
imgCb01.Source = myBitmapImage;
Canvas.SetLeft(imgCb01, 152d);//This aint working
Canvas.SetTop(imgCb01, 285.0);//This aint working
Thickness margin = imgCb01.Margin;//I thought this lines would move my image
margin.Left = (imgCb01.Margin.Left) + 5;//slightly to the right
imgCb01.Margin = margin;//and they do but they are hiding (TT-TT) ...

所以我有这段代码,既不工作SetLeft也不SetTop工作,我想我可以做修改边距的技巧,但随后图像“向前”移动,而图像控件保持其位置,因此看起来图像刚刚变得不可见。

标签: c#.netwpf

解决方案


好吧,我认为这只是来自 Microsoft Visual Studio 的一些奇怪的随机错误,我刚刚在其他 PC 上重新开始复制​​ XAML,它工作得很好......抱歉打扰你了 :')


推荐阅读