Limitations of TemplateBinding

A user control (written under VS 2008) has the SelectedColor Dependency property, and its control template contains the following:

... <Rectangle> <Rectangle.Fill> <SolidColorBrush Color="{TemplateBinding SelectedColor}"/> </Rectangle.Fill> </Rectangle> ... 

A rectangle does not have the correct color if the snap is not related to:

 ... <Rectangle> <Rectangle.Fill> <SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/> </Rectangle.Fill> </Rectangle> ... 

Well, I know that TemplateBinding is a simplified version of Binding, and it has a set of restrictions, so what is the restriction that makes the above code not work?

+4
source share
1 answer

TemplateBinding is very different. Think of them as simply assigning a value when applying a pattern. Since you SelectedItem change at run time, you need a real binding to notify you of a property change.

+2
source

All Articles