如何显示图像&如果在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'
}
}
答案 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"));
}
}