How to find out Exact Control in WPF DataGridColoumnHeader Style

73 views Asked by At

I'm having a DataGridColumnHeader Sytle, in that I'm having a Button for Filtering. I need to find out which button is currently working (i.e., which button gets fired), based on that I need to write trigger action for that appropriate Button.

My XAML Style is

<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="DummyFilterDataGridColumnHeader">
   <Setter Property="Template">
      <Setter.Value>
          <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
              <Button Command="{Binding Path=DataContext.FilterPopUpCommand, 
                                  RelativeSource={RelativeSource Mode=FindAncestor, 
                                                  AncestorType={x:Type Window}}}">
                  <Button.CommandParameter>
                      <MultiBinding Converter="{StaticResource MultiValueConverterKey}">
                          <Binding RelativeSource="{ RelativeSource Mode=FindAncestor, 
                                                     AncestorType={x:Type cust:DataGrid}}" />
                          <Binding Path="Column" 
                                   RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                      </MultiBinding>
                  </Button.CommandParameter>
              </Button>
          </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>

Note: I need to set Button Visibility based on Button Click. After Clicking the Popup gets display after the Popup gets Closed then I want to set the Visibility to Collapsed.

1

There are 1 answers

5
Felix D. On

EDIT:

Add the Button itself to the <Button.CommandParameters/>

<Button Command="{Binding Command}" 
        CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />

This will get you the Button itself to your Method you are calling if clicked.

Inside your ClickEventHandler, where you open the PopUp you can set the Visibility for the Button you got from the parameters.

Hope this helps