WPF-BitmapEffect上的编程绑定

WPF-BitmapEffect上的编程绑定,wpf,data-binding,bitmapeffect,Wpf,Data Binding,Bitmapeffect,我希望能够以编程方式将一些数据绑定到位图效果上的依赖项属性。对于类似TextBlock的FrameworkElement,有一种SetBinding方法,您可以通过编程方式执行以下绑定: myTextBlock.SetBinding(TextBlock.TextProperty, new Binding("SomeProperty")); 我知道你可以直接用XAML实现(如下所示) 但它不起作用。您可以使用: 我想那应该是你想要的 <TextBlock Width="Auto" Text

我希望能够以编程方式将一些数据绑定到位图效果上的依赖项属性。对于类似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>
myTextBlock.SetBinding(OuterGlowBitmapEffect.GlowSize, new Binding("SomeProperty") { Source = someObject });
Binding newBinding = new Binding();
newBinding.ElementName = "SomeObject";
newBinding.Path = new PropertyPath(SomeObjectType.SomeProperty);
BindingOperations.SetBinding(MyGlow, OuterGlowBitmapEffect.GlowSizeProperty, newBinding);