I am trying to hide the display of the Expander ToggleButton based on a Boolean property of the row data binding type. I have implemented the ToggleButton Style so it changes it's rendering based on the IsEnabled property, and bound this to the Expander's IsEnabled with this:
<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=IsEnabled}" />
</Style>
I then try to bind to the Expander's IsEnabled like this:
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Expander Expanded="Expander_Expanded" Collapsed="Expander_Collapsed" Style="{StaticResource DataGridRowHeaderExpander1}"
IsEnabled="{Binding IsDistributed}">
</Expander>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
If I hard code the IsEnabled to true or false the rendering works perfectly. Also, all the other row bindings work as expected. In this case I get the following errors :
System.Windows.Data Warning: 67 : BindingExpression (hash=63415529): Resolving source (last chance)
System.Windows.Data Warning: 70 : BindingExpression (hash=63415529): Found data context element: Expander (hash=22324024) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=63415529): Activate with root item <null>
System.Windows.Data Warning: 106 : BindingExpression (hash=63415529): Item at level 0 is null - no accessor
System.Windows.Data Warning: 80 : BindingExpression (hash=63415529): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 88 : BindingExpression (hash=63415529): TransferValue - using fallback/default value 'True'
System.Windows.Data Warning: 89 : BindingExpression (hash=63415529): TransferValue - using final value 'True'