I am trying to attach a datatrigger on one of my combobox element. The trigger should read the attached property of the DataGridTextColumn (combobox's ancestor) and take decision based on that. Now the problem is that the DataGridTextColumn isn't part of Visual Tree so I cannot get it by RelativeSource Ancestor. Here is sample code.
<ComboBox Name="cmbFilter" DisplayMemberPath="CategoryName">
<ComboBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridTextColumn}},
Path=Header}"
Value="Id">
<Setter Property="Control.Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
Any one maybe suggest some alternative
Edit:
@denis I don't really understand your solution, so let me explain in detail. I am developing a general purpose filter that would apply to all DataGrid's that need the filtering functionality. The DataGrid definition will specify whether it wants filtering or not by specifying custom attached property "IsFilterable" on DataGrid. Individual DataGridColum will specify what kind of filter they want (combobox or textbox) by specifying "FilterDisplayType" on DataGridColumn. The DataGrid will know nothing other than above. All the functionality will then be handled by the Filter based on the above attached properties on DataGrid and DataGridColumn (all types of columns).