2017-03-16 31 views
0

我試圖通過C#中的後臺代碼添加ContentControl,但未能通過代碼將圖像插入ContentControl從C#代碼中向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; 

如何把ACimageContentControl

回答

0

試試這個:

myContentControl.Content=ACimage;