Reputation: 13417
I have a wpf Canvas
in a grid in a UserControl
named 'root' and I bind the Width
and Height
of the canvas as follows:
Width="{Binding ElementName=root, Path=ActualWidth}"
Height="{Binding ElementName=root, Path=ActualHeight}"
On the canvas all kinds of DrawingVisual
are drawn.
In code behind I set the Width end Height of my Canvas equal to ContentBounds.Right
and ContentBounds.Bottom
so that every DrawingVisual
that I add to the canvas will be visible.
This seems to work all right but I am confused about the binding mentioned.
This is a one-way binding from the usercontrol's actual size to the size of the canvas.
Does the setting of Width and Height in code behind overrule this binding?
When I remove the binding the canvas is displayed equally as well, but the control is also used in other places and situations and might be needed then.
Upvotes: 0
Views: 502
Reputation: 169400
Does the setting of
Width
andHeight
in code behind overrule this binding?
Yes. Programmatically setting the value of a target property that has a one-way binding applied to it will clear the binding.
Upvotes: 1