繁体   English   中英

从后面的C#代码向ContentControl添加图像源

[英]Add an image source to ContentControl from C# code behind

我试图通过C#中的后台代码添加ContentControl ,但是无法通过代码将图像放入ContentControl

这是Xaml中的工作代码

<ContentControl x:Name="cControl" Width="200"
              Height="200"
              Canvas.Left="210"
              Canvas.Top="220"
              Style="{StaticResource DesignerItemStyle}">
      <Image IsHitTestVisible="False" Stretch="Fill" Source="pack://application:,,,../Resources/ACImages/737.png"/>
</ContentControl>

到目前为止,在C#中我拥有的是:

 Image ACimage = new Image();
 BitmapImage image = new BitmapImage();
 image.BeginInit();
 image.UriSource = new Uri("pack://application:,,,../Resources/ACImages/737.png");
 image.EndInit();
 ACimage.Source = image;

 ContentControl myContentControl = new ContentControl();
 Style s = this.FindResource("DesignerItemStyle") as Style;
 myContentControl.Style = s;

如何将ACimage放入ContentControl

尝试这个 :

myContentControl.Content=ACimage;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM