0
s.jpg通過BuildAction == Resource添加到解決方案中。Silverlight:如何動態繪製圖像?
XAML
<UserControl x:Class=...>
<Canvas x:Name="LayoutRoot">
</Canvas>
</UserControl>
CS
Image Model = new Image();
Model.Source = new BitmapImage(new Uri("/s.jpg", UriKind.Relative));
LayoutRoot.SetLeft(Model, Coor.X);
LayoutRoot.SetTop(Model, Coor.Y);
Model.Width = 50;
Model.Height = 30;
LayoutRoot.Children.Add(Model);
我的問題是:人是我的形象?它has't出現在屏幕上,但如果我改變XAML來
<UserControl x:Class=...>
<Canvas x:Name="LayoutRoot">
<Image Source="s.jpg"></Image>
</Canvas>
</UserControl>
你可以看到它,如果還設置CS爲
Ellipse Model = new Ellipse();
Model.Fill = new SolidColorBrush(Colors.Gray);
Model.Stroke = new SolidColorBrush(Colors.Blue);
LayoutRoot.SetLeft(Model, Coor.X);
LayoutRoot.SetTop(Model, Coor.Y);
Model.Width = 50;
Model.Height = 30;
LayoutRoot.Children.Add(Model);
我會看到橢圓。那麼問題是什麼?