c# - Binding on a nested property without using XAML -
how make binding on nested target property, shape.stroke.color in wpf without using xaml ?
for simple property i'm using code looking :
var binding = new binding("mysourceproperty"); binding.source = mysourceobject; mytargetobject.setbinding(mytargetproperty, binding); where mytargetproperty can be, example, shape.strokeproperty. now, how can same thing on colorproperty of stroke of shape ?
provided shape's stroke property holds solidcolorbrush, can use static bindingoperations.setbinding method:
var shape = new path(); // or whatever var binding = new binding { source = colors.red }; // or whatever bindingoperations.setbinding(shape.stroke, solidcolorbrush.colorproperty, binding);
Comments
Post a Comment