I'm having an issue with setting an Image.Source binding in the code behind file.
If create the elements in XAML and define the binding there, it works perfectly. But I need to be able to add the elements at runtime, and when I try to do this the Image doesn't update when the source is changed. Here's what I've got in the XAML:
<Canvas x:Name="parentCanvas"/>
And here's what have in the code-behind:
Canvas childCanvas;
WriteableBitmap source;
private void Method()
{
this.childCanvas = new Canvas();
Binding b = new Binding();
b.source = this.source;
Image img = new Image();
img.SetBinding(Image.SourceProperty, b);
this.childCanvas.Children.Add(img);
this.parentCanvas.Children.Add(this.childCanvas);
}
So again, when I bind the Image.Source in XAML to "img", it updates the Image anytime I change the WriteableBitmap. But adding them in code, it won't refresh. Also, if I asign a WriteableBitmap to "img", and THEN bind the new Image.Source to it, the Image shows up. But as soon as I assign a new WriteableBitmap to "img", the previous image stays displayed.
If create the elements in XAML and define the binding there, it works perfectly. But I need to be able to add the elements at runtime, and when I try to do this the Image doesn't update when the source is changed. Here's what I've got in the XAML:
<Canvas x:Name="parentCanvas"/>
And here's what have in the code-behind:
Canvas childCanvas;
WriteableBitmap source;
private void Method()
{
this.childCanvas = new Canvas();
Binding b = new Binding();
b.source = this.source;
Image img = new Image();
img.SetBinding(Image.SourceProperty, b);
this.childCanvas.Children.Add(img);
this.parentCanvas.Children.Add(this.childCanvas);
}
So again, when I bind the Image.Source in XAML to "img", it updates the Image anytime I change the WriteableBitmap. But adding them in code, it won't refresh. Also, if I asign a WriteableBitmap to "img", and THEN bind the new Image.Source to it, the Image shows up. But as soon as I assign a new WriteableBitmap to "img", the previous image stays displayed.