如何将Background属性绑定到代码中的WriteableBitmap?

时间:2014-05-29 15:03:40

标签: c# xaml windows-phone-8 data-binding

我试图将Border元素的Background属性绑定到代码中WriteableBitmap类型的属性。

将Image写成WriteableBitmap,我尝试以下操作但没有成功,因此,边框显示没有任何背景:

Binding b = new Binding();
b.Source = dataContext.Image;
myBorder.SetBinding(Border.BackgroundProperty, b);

dataContext.Image = new WriteableBitmap(1, 1);
dataContext.Image.SetSource(e.ChosenPhoto);

我错过了什么?

1 个答案:

答案 0 :(得分:0)

我不确定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