I am trying to resolve a number of frequently occurring data binding errors as given below
System.Windows.Data Error: 40 : BindingExpression path error: 'Active' property not found on 'object' ''FrameViewModel' (HashCode=55649279)'. BindingExpression:Path=Active; DataItem='FrameViewModel' (HashCode=55649279); target element is 'ContentControl' (Name='HeaderBorder'); target property is 'NoTarget' (type 'Object')
I have an attached dependency property Active
public bool Active
{
get
{
return (bool)GetValue(ActiveProperty);
}
set
{
SetValue(ActiveProperty, value);
}
}
public static readonly DependencyProperty ActiveProperty
= DependencyProperty.RegisterAttached("Active", typeof(bool), typeof(Card));
The binding is set in theme files in a control template
<ControlTemplate x:Key="FrameHeader" TargetType="ContentControl">
.....
.....
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Active}" Value="True">
<Setter TargetName="HeaderBackground" Property="Background" Value="{DynamicResource SelectedHeaderBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Active}" Value="False">
<Setter TargetName="HeaderBackground" Property="Background" Value="{DynamicResource HeaderBrush}"/>
</DataTrigger>
</ControlTemplate.Triggers>
The control template is used in a content control as shown here (can be seen in the error as well)
<ControlTemplate x:Key="Card" TargetType="{x:Type Button}">
<ContentControl Template="{DynamicResource FrameTemplate}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ContentControl Template="{DynamicResource FrameHeader}" Grid.Row="0" x:Name="HeaderBorder" >
<Border Style="{DynamicResource BorderTop}">
<DockPanel>
<ContentPresenter x:Name="UpperLeftContent"
DockPanel.Dock="Left"
Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=icush:Frame},
Converter={StaticResource WatchListLockoutTimerVisibilityConverter},
Path=UpperLeftContent}"
Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=icush:Frame},
Converter={StaticResource WatchListLockoutTimerConverter},
ConverterParameter={StaticResource LockoutTimerRadius},
Path=UpperLeftContent}"
/>
<TextBlock x:Name="Header"
Style="{DynamicResource Header}"
Text="{Binding Path=Title}" />
</DockPanel>
</Border>
</ContentControl>
<ContentControl Template="{DynamicResource FrameBody}" Grid.Row="1" Content="{TemplateBinding Content}"/>
</Grid>
</ContentControl>
</ControlTemplate>
I have spent a lot of time trying to figure out if the DependencyProperty is missing anything or if the binding is set incorrectly but to no avail. The application works as expected but I'm trying to get rid of such binding errors. The error goes away if I remove the binding in XML but that is not the solution I'm looking for. There might be something wrong with the binding.
I have looked at several other posts, read material and book chapters on Dependency Properties and binding and I can't find any obvious mistake. I have even used snoop but didn't get any additional information from that too. Some of the things I've looked at are given below
BindingExpression path error: property not found on 'object'
System.Windows.Data Error: 40 : BindingExpression path error: property not found on object
WPF Error 40 BindingExpression path error: property not found on 'object'
http://wpftutorial.net/DependencyProperties.html
http://rachel53461.wordpress.com/2012/07/14/what-is-this-datacontext-you-speak-of/
Is there a way to determine where a WPF Binding is declared/created?
WPF slow performance - many DataItem=null binding warnings
Any ideas of what could be going wrong and how I can get rid of the error?