In a DataTemplate I want to show the Control which is actually replaced by the DataTemplate. With error validation, this is possible by using <AdornedElementPlaceHolder />
. However, this seems not to work in a normal DataTempl开发者_开发百科ate.
I think there would be a simple solution, but just can't find it.
Thanks a lot
This is not possible and here is why. DataTemplate
doesn't replace anything. Instead, a control that defines a DataTemplate contains the content provided by it. If it was possible then there would be an infinite loop (control -> data template -> control -> data template -> ...).
I suggest you read the following article to fully understand data templates: http://msdn.microsoft.com/en-us/library/ms742521.aspx
A DataTemplate in some sense "replaces" a data object and not a UI object - in other words, not a Control. If you are trying to work with properties of the Control (usually either a ContentControl or ItemsControl) that is using the template, try a RelativeSource Binding where the AncestorType is the type of the Control.
精彩评论