2008-09-12 10 views
5

ja jak móc programowo wiążą jakieś dane do właściwości zależność od BitmapEffect. Z FrameworkElement jak TextBlock istnieje metoda SetBinding gdzie można programowo robić te wiązania jak:WPF - programowa Wiązanie analizowano na BitmapEffect

myTextBlock.SetBinding(TextBlock.TextProperty, new Binding("SomeProperty")); 

I wiem, że można to zrobić w prosty XAML (jak widać poniżej)

<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> 

Ale nie można dowiedzieć się, jak to zrobić z C#, ponieważ BitmapEffect nie ma metody SetBinding.

Próbowałem:

myTextBlock.SetBinding(OuterGlowBitmapEffect.GlowSize, new Binding("SomeProperty") { Source = someObject }); 

Ale to nie działa.

Odpowiedz

11

Można użyć BindingOperation.SetBinding:

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

myślę, że powinni robić, co chcesz.