0

これは、画像を動的にバインドしている間は機能しません

Image Imgsource = new Image();

Imgsource.Source = new BitmapImage(new Uri("/Finder;component/Images/Chrysanthemum.png", UriKind.RelativeOrAbsolute));

前もって感謝します

4

4 に答える 4

1

あなたのコードはImage要素を作成します。ただし、その要素をページ内のコンテナーに追加する必要があります。たとえば、LayoutRootグリッドに対して:

Image Imgsource = new Image();
Imgsource.Source = new BitmapImage(new Uri("/Finder;component/Images/Chrysanthemum.png", UriKind.RelativeOrAbsolute));
this.LayoutRoot.Children.Add(Imgsource);
于 2013-05-24T08:24:42.270 に答える
1

これを試してください...

  public void setimagebackgroud(string uri)
    {
        ImageBrush imageBrush = new ImageBrush();
        Image image = new Image();
        image.Source = new BitmapImage(new Uri(uri,UriKind.RelativeOrAbsolute));
        imageBrush.ImageSource = image.Source;
    }
于 2013-05-27T05:34:19.133 に答える
1

画像コンバーターを介してバインドする必要があります:

 public class ImageConverter : IValueConverter
 {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
           MemoryStream memStream = new MemoryStream((byte[])value,false);
           BitmapImage empImage = new BitmapImage();
           empImage.SetSource(memStream);
           return empImage; 
      }
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
           throw new NotImplementedException();
      }
 }
于 2013-05-26T10:20:44.483 に答える
-2
 The binding as it should be done

 string s = "Hello";

 //Create the binding description   
 Binding b = new Binding("");   
 b.Mode = BindingMode.OneTime;   
 b.Source = s;

 //Attach the binding to the target  
 MyText.SetBinding(TextBlock.TextProperty, b);

 See if this helps
于 2013-05-24T08:32:11.713 に答える