2008-09-12 5 views
5

にバインド私はBitmapEffectプログラムでバインドに依存関係プロパティにいくつかのデータをできるようにしたいと思います。 TextBlockのようなのFrameworkElementを使用すると、プログラムのようにこれらのバインディングを行うことができますSetBinding方法があります:- プログラマがBitmapEffect

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 }); 
をしかし、それは動作しません。

答えて

11

あなたはBindingOperation.SetBindingを使用することができます。

Binding newBinding = new Binding(); 
newBinding.ElementName = "SomeObject"; 
newBinding.Path = new PropertyPath(SomeObjectType.SomeProperty); 
BindingOperations.SetBinding(MyGlow, OuterGlowBitmapEffect.GlowSizeProperty, newBinding); 

私はそれはあなたがやりたいことだと思います。

関連する問題