2008-09-12 14 views
5

Me gustaría ser capaz de programación se unen algunos datos a las propiedades de dependencia en un BitmapEffect. Con un FrameworkElement como TextBlock hay un método SetBinding donde mediante programación puede hacer estos enlaces como:WPF - programático Encuadernación en un BitmapEffect

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

Y sé que puedes hacerlo en XAML recta (como se verá más adelante)

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

Pero no se puede averiguar cómo lograr esto con C# porque BitmapEffect no tiene un método SetBinding.

que he probado:

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

Pero no funciona.

Respuesta

11

Puede utilizar BindingOperation.SetBinding:

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

creo que debería hacer lo que quiera.

Cuestiones relacionadas