TemplateBinding to Binding

If you've ever written a WPF or Silverlight control template, chances are that you've used TemplateBinding. However, there are times where those bindings simply don't work compared to a Binding with a TemplatedParent RelativeSource. Those cases are when you want a property path, when the bound property type mismatches, when the binding mode must be specified, and a few others.

GammaXaml adds two context actions, available for both WPF and Silverlight:
  • Convert a TemplateBinding to a Binding with a TemplatedParent relative source.
  • Convert a Binding with a TemplatedParent relative source to a TemplateBinding.


RelativeSource to x:Static

In WPF RelativeSource contains three static members: Self, TemplatedParent and PreviousData. The documentation states:

Three of the four RelativeSourceMode values, PreviousData, Self, or TemplatedParent, can produce a RelativeSource that is wholly static, containing no unique private values. All uses of the static property can share the same object, eliminating the need to allocate separate objects for each use. Therefore, using the static property reduces memory usage.

That's why GammaXaml adds an highlighting and a quick fix when the usage of those static properties is possible. There are also two context actions available for convenience:
  • Convert from RelativeSource to x:Static
  • Convert from x:Static to RelativeSource

The actions, highlighting and quick fix aren't available in Silverlight since the RelativeSource static members are specific to WPF.


Last edited Mar 3, 2012 at 3:59 PM by MrJul, version 7


No comments yet.