Why does the following piece of XAML give me a XamlParseException with the (meaningless) message "Expression type is not a valid Style value." at runtime?
<Control x:Class="TestApp.Max.MyControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Max="clr-namespace:TestApp.Max" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Control.Template> <ControlTemplate> <TextBlock Name="txt" Text="{TemplateBinding Max:MyControl.Foo}" /> <ControlTemplate.Triggers> <Trigger Property="Control.IsMouseOver" Value="True"> <Setter TargetName="txt" Property="Text" Value="{TemplateBinding Max:MyControl.Bar}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Control.Template> </Control> The offending line is
<Setter TargetName="txt" Property="Text" Value="{TemplateBinding Max:MyControl.Bar}" /> If I replace the TemplateBinding with a normal Binding it starts to work:
{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text2} Shouldn't I be able to use a TemplateBinding since I am within a ControlTemplate? And what does the exception message really mean?