显示器和显示器使用作为URL传入的参数设置默认图像

时间:2011-08-11 13:57:12

标签: c# xaml

如何显示图像&如果在Silverlight 2.0控件中@'_imageURL'中没有传递任何内容,请设置图像?假设我有一个以字符串形式传递的URL(_imageURL)@ Page.xaml.cs,这是我的片段:

public Page(string _setLayout, string _imageURL, string _setTitleText, string _setDescriptionText)
    {
        InitializeComponent();

        if (!string.IsNullOrEmpty(_imageURL))
        {
            //(image to display on load)
        }
        if (string.IsNullOrEmpty(_imageURL))
        {
            //image to display if no parameter passed in @ '_imageURL'
        }            
    }

1 个答案:

答案 0 :(得分:0)

假设您在Image的xaml中声明了Page,就像这样:

<Image x:Name="MyImage"/>

然后:

public Page(string _setLayout, string _imageURL, string _setTitleText, string _setDescriptionText)
{
    InitializeComponent();

    if (!string.IsNullOrEmpty(_imageURL))
    {
        MyImage.Source = new BitmapImage(new Uri(_imageURL));
    }
    if (string.IsNullOrEmpty(_imageURL))
    {
        MyImage.Source = new BitmapImage(new Uri("Some\path\to\default\image.png"));
    }            
}