silverlight 图片引入代码

时间:2024-04-15 09:17:43

private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string str = this.comboBox2.SelectedIndex.ToString() ;
//MessageBox.Show(str);

//if (str == "1")
if (str.Equals("1"))
{
//Image myImage3 = new Image();
//BitmapImage bi3 = new BitmapImage();
////bi3.BeginInit();
//bi3.UriSource = new Uri("../Image2/19guolvsheshi.png", UriKind.Relative);
////bi3.EndInit();
//myImage3.Stretch = Stretch.Fill;
//myImage3.Source = bi3;
//this.image2 = myImage3;

MessageBox.Show(str+"if");
//Image myImage3 = new Image();
BitmapImage bi3 = new BitmapImage();
//bi3.BeginInit();
bi3.UriSource = new Uri("../../../Image2/20guolvsheshi.png", UriKind.RelativeOrAbsolute);
//bi3.EndInit();
//myImage3.Stretch = Stretch.Fill;
//myImage3.Source = bi3;
//this.image2 = myImage3;

//this.image2 = new Image();
image2.Stretch = Stretch.Fill;
//image2.Source = bi3;
this.image2.Source = bi3;
}
else {
////Image myImage3 = new Image();
//BitmapImage bi3 = new BitmapImage();
////bi3.BeginInit();
//bi3.UriSource = new Uri("/Image2/20guolvsheshi.png", UriKind.RelativeOrAbsolute);
////bi3.EndInit();
////myImage3.Stretch = Stretch.Fill;
////myImage3.Source = bi3;
////this.image2 = myImage3;

MessageBox.Show(str + "else");
BitmapImage bi3 = new BitmapImage();
bi3.UriSource = new Uri("../Image2/20guolvsheshi.png", UriKind.RelativeOrAbsolute);
//this.image1 = new Image();
//image1.Stretch = Stretch.Fill;
image1.Source = bi3;

}
}