【问题标题】:Silverlight: How to draw images dynamically?Silverlight:如何动态绘制图像?
【发布时间】:2010-02-19 04:33:43
【问题描述】:

s.jpg 通过 BuildAction==Resource 添加到解决方案中。

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);

这是我的问题:是我的形象吗?它没有出现在屏幕上,但如果我将 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);

我会看到那个椭圆。那么问题是什么?

【问题讨论】:

    标签: c# image silverlight-2.0


    【解决方案1】:

    试试:

    ImageSource imgSrc = new BitmapImage(new Uri("http://server/path/s.jpg", UriKind.RelativeOrAbsolute));

    LayoutRoot.Children.Add(imgSrc); LayoutRoot.UpdateLayout();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多