我有一个DataGrid,其中所有列都使用相同的HeaderTemplate。该HeaderTemplate有一个DropDownButton,可以打开一个DropDown。该Dropdown具有每个都有一个单击处理程序的项。我需要将列的SortMemberPath传递给项目单击处理程序。
怎么做?
当前尝试:
<Popup.Style>
<Style TargetType="{x:Type Popup}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=myButton, Path=IsMouseOver}" Value="True" />
<Condition Binding="{Binding ElementName=myItemsControl, Path=IsMouseOver}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="IsOpen" Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
<Border BorderThickness="1" BorderBrush="Black" Background="White">
<ItemsControl ItemsSource="{Binding ElementName=myButton, Path=DropDown.Items}" />
</Border>
</Popup>
<DataTemplate x:Key="ColumnFilterHeaderTemplate">
<Grid Width="{Binding ElementName=DeviceColumn, Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="5"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}, Path=Content}" Grid.Column="1" HorizontalAlignment="Left"/>
<local:DropDownButton x:Name="filterDropDownButton" Content="..." local:MouseOverHelper.Observe="True"
Width="30" Background="Transparent" Grid.Column="3" BorderBrush="Transparent" HorizontalAlignment="Right">
<local:DropDownButton.DropDown>
<ItemsControl x:Name="itemsControl" Background="White">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<MenuItem Header="Option 1" Click="Option1_Click" Foreground="Black"/>
<MenuItem Header="Option 2" Click="Option2_Click" Foreground="Black"/>
<MenuItem Header="Filter" Click="FilterOption_Click" Foreground="Black" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=DataGridColumn}, Path=SortMemberPath}"/>
</ItemsControl>
</local:DropDownButton.DropDown>
</local:DropDownButton>
</Grid>
</DataTemplate>
<DataGridTemplateColumn Header="Device" SortMemberPath="Name" Width="*" x:Name="DeviceColumn" HeaderTemplate="{StaticResource ColumnFilterHeaderTemplate}"/>
字符串
在我的代码隐藏中,CommandParameter的值为null
private void FilterOption_Click(object sender, RoutedEventArgs e)
{
MenuItem menuItem = sender as MenuItem;
string sortMemberPath = menuItem.CommandParameter as string;
}
型
1条答案
按热度按时间uxhixvfz1#
DataGridColumn
不是MenuItem
的视觉祖先,但DataGridColumnHeader
可能依赖于DropDownButton
的实现:字符串