开发者

display & set default image with parameter passed in as URL

How do I display an image & set an image if nothing is passed in @ '_imageURL', in a Silverlight 2.0 control? Assuming that i have an url passed in as a string (_imageURL) @ Page.xaml.cs, here is my snippet:

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'
        }            
    }


Assuming you have an Image declared in the xaml of the Page, like this:

<Image x:Name="MyImage"/>

Then:

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"));
    }            
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜