如何在代码中添加绑定?
<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>
我尝试没有成功:
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
答案 0 :(得分:1)
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...
答案 1 :(得分:0)
我找到了解决方案:
GreenscreenEffect effect = new GreenscreenEffect() ;
Binding binding = new Binding();
binding.Path = new PropertyPath("Value");
binding.Source = sliderGreenscreenTolerance;
BindingOperations.SetBinding(effect, GreenscreenEffect.ToleranceProperty, binding);