Reputation: 4964
I have the following binding in my XAML file:
Fill="{Binding ElementName=cpRange1, Path=CurrentColor}"
What would be the syntax for setting this same building but in execution time?
Upvotes: 0
Views: 191
Reputation: 8656
It's not entirely clear what you're trying to achieve. If you're trying to set binding on your object at runtime in the code behind, you should be able to do this:
For a given Rectangle
<Rectangle Name="MyRect"/>
In your code:
// Property to bind (example)....
public SolidColorBrush MyColor { get; set; }
//
// In some initialisation method.
MyColor = new SolidColorBrush(Colors.Blue);
Binding myBinding = new Binding("MyColor");
MyRect.SetBinding(Rectangle.FillProperty, myBinding);
In your specific case, you would want to set myBinding.ElementName
, and point myBinding.Path
at a property on the element you wish to target.
I may have misunderstood your goal.
Upvotes: 1