Reputation: 35733
How can I add a binding in code behind?
<Canvas.Effect >
<fx:GreenscreenEffect Tolerance="{Binding Value, ElementName=sliderGreenscreenTolerance}"
ColorR="{Binding Value, ElementName=sliderGreenscreenR}"
ColorG="{Binding Value, ElementName=sliderGreenscreenG}"
ColorB="{Binding Value, ElementName=sliderGreenscreenB}" />
</Canvas.Effect>
I tried without success:
GreenscreenEffect effect = new GreenscreenEffect() ;
Binding binding = new Binding();
binding.Path = new PropertyPath("Tolerance");
binding.Source = sliderGreenscreenTolerance.Value;
BindingOperations.SetBinding(effect, TextBlock.TextProperty, binding);
// etc. for each property
Upvotes: 1
Views: 6517
Reputation: 4934
GreenscreenEffect effect = new GreenscreenEffect() ;
Binding binding = new Binding();
binding.Path = new PropertyPath("Value");
binding.Source = sliderGreenscreenTolerance;
// effect.SetBinding(GreenscreenEffect.ToleranceProperty, binding);
// Commented above out since GreenscreenEffect is not a FrameworkElement, thus:
BindingOperations.SetBinding(effect, GreenscreenEffect.ToleranceProperty, binding);
// ... ColorRProperty etc...
Upvotes: 2
Reputation: 35733
I found the solution:
GreenscreenEffect effect = new GreenscreenEffect() ;
Binding binding = new Binding();
binding.Path = new PropertyPath("Value");
binding.Source = sliderGreenscreenTolerance;
BindingOperations.SetBinding(effect, GreenscreenEffect.ToleranceProperty, binding);
Upvotes: 0