C# 如何将后台属性绑定到代码中的WriteableBitmap?
我试图在代码中将Border元素的Background属性绑定到WriteableBitmap类型的属性 作为WriteableBitmap的图像,我尝试了以下操作,但没有成功,因此,边框显示时没有任何背景:C# 如何将后台属性绑定到代码中的WriteableBitmap?,c#,xaml,windows-phone-8,data-binding,C#,Xaml,Windows Phone 8,Data Binding,我试图在代码中将Border元素的Background属性绑定到WriteableBitmap类型的属性 作为WriteableBitmap的图像,我尝试了以下操作,但没有成功,因此,边框显示时没有任何背景: Binding b = new Binding(); b.Source = dataContext.Image; myBorder.SetBinding(Border.BackgroundProperty, b); dataContext.Image = new WriteableBit
Binding b = new Binding();
b.Source = dataContext.Image;
myBorder.SetBinding(Border.BackgroundProperty, b);
dataContext.Image = new WriteableBitmap(1, 1);
dataContext.Image.SetSource(e.ChosenPhoto);
我遗漏了什么?我不确定
Image
是否是您的财产,但您可以这样尝试:
Binding b = new Binding();
b.Path = new PropertyPath("Image"); // Image should be a public property in your datacontext
b.Source = dataContext;
myBorder.SetBinding(Border.BackgroundProperty, b);
dataContext.Image = new WriteableBitmap(1, 1);
dataContext.Image.SetSource(e.ChosenPhoto);
RaiseProperty("Image"); //raise property change