开发者

display & set default image with parameter passed in as URL

开发者 https://www.devze.com 2023-03-27 16:04 出处:网络
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 i

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

精彩评论

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