Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement