WPF - BitmapEffect의 프로그래밍 방식 바인딩
-
09-06-2019 - |
문제
나는 할 수 있기를 원한다 프로그래밍 방식으로 일부 데이터를 종속성 속성에 바인딩합니다. 비트맵효과.TextBlock과 같은 FrameworkElement에는 다음과 같은 바인딩을 프로그래밍 방식으로 수행할 수 있는 SetBinding 메서드가 있습니다.
myTextBlock.SetBinding(TextBlock.TextProperty, new Binding("SomeProperty"));
그리고 나는 당신이 바로 XAML로 그것을 할 수 있다는 것을 알고 있습니다(아래 참조)
<TextBlock Width="Auto" Text="Some Content" x:Name="MyTextBlock" TextWrapping="Wrap" >
<TextBlock.BitmapEffect>
<BitmapEffectGroup>
<OuterGlowBitmapEffect x:Name="MyGlow" GlowColor="White" GlowSize="{Binding Path=MyValue}" />
</BitmapEffectGroup>
</TextBlock.BitmapEffect>
</TextBlock>
하지만 BitmapEffect에는 SetBinding 메서드가 없기 때문에 C#으로 이 작업을 수행하는 방법을 알 수 없습니다.
난 노력 했어:
myTextBlock.SetBinding(OuterGlowBitmapEffect.GlowSize, new Binding("SomeProperty") { Source = someObject });
하지만 작동하지 않습니다.
해결책
당신이 사용할 수있는 BindingOperation.SetBinding:
Binding newBinding = new Binding();
newBinding.ElementName = "SomeObject";
newBinding.Path = new PropertyPath(SomeObjectType.SomeProperty);
BindingOperations.SetBinding(MyGlow, OuterGlowBitmapEffect.GlowSizeProperty, newBinding);
나는 그것이 당신이 원하는 것을 해야 한다고 생각합니다.
제휴하지 않습니다 StackOverflow