从后面的 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;