これは、画像を動的にバインドしている間は機能しません
Image Imgsource = new Image();
Imgsource.Source = new BitmapImage(new Uri("/Finder;component/Images/Chrysanthemum.png", UriKind.RelativeOrAbsolute));
前もって感謝します
これは、画像を動的にバインドしている間は機能しません
Image Imgsource = new Image();
Imgsource.Source = new BitmapImage(new Uri("/Finder;component/Images/Chrysanthemum.png", UriKind.RelativeOrAbsolute));
前もって感謝します
あなたのコードはImage
要素を作成します。ただし、その要素をページ内のコンテナーに追加する必要があります。たとえば、LayoutRoot
グリッドに対して:
Image Imgsource = new Image();
Imgsource.Source = new BitmapImage(new Uri("/Finder;component/Images/Chrysanthemum.png", UriKind.RelativeOrAbsolute));
this.LayoutRoot.Children.Add(Imgsource);
これを試してください...
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;
}
画像コンバーターを介してバインドする必要があります:
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();
}
}
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