SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <TextBlock x:Name="MyTextBlock" TextWrapping="Wrap" Text="{Binding TextProperty, Converter={StaticResource MyConverter}}"/>
  2.    
  3. if (converter = x)
  4.     converter = y;
  5. else
  6.     converter = x;
  7.    
  8. //For WPF:
  9. // var binding = BindingOperations.GetBindingBase(
  10. //     MyTextBlock,
  11. //     TextBlock.TextProperty);
  12.  
  13. //For SilverLight we have to use the expression:
  14. var expr = MyTextBlock.GetBindingExpression(TextBlock.TextProperty);
  15. if (expr != null)
  16. {
  17.     // for Silverlight we have to use the ParentBinding of the expression
  18.     var binding = expr.ParentBinding;
  19.     binding.Converter = yourLogicHere;
  20.  
  21.     // in WPF there are 3 types of bindings
  22.     /*
  23.     else if (binding is MultiBinding)
  24.     {
  25.         ((MultiBinding)binding).Converter = yourMultiLogicHere;
  26.     }
  27.     else if (binding is PriorityBinding)
  28.     {
  29.         foreach (var childBinding in ((PriorityBinding)binding).Bindings)
  30.         {
  31.             ((Binding)childBinding).Converter = yourLogicHere;
  32.         }
  33.     }
  34.     */
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top