显示,设置默认图像,参数作为URL传入

本文关键字:URL 传入 图像 设置 默认 显示 参数 | 更新日期: 2023-09-27 18:05:31

如何显示图像&设置一个图像,如果没有在@ '_imageURL'中传递,在Silverlight 2.0控件?假设我有一个url作为字符串(_imageURL) @ page . example .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'
        }            
    }

显示,设置默认图像,参数作为URL传入

假设在Page的xaml中声明了Image,如下所示:

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