我想在WPF中的Datagrid列标题中更改我的图标。 (例如,过滤Excel)
我有一个包含3列的数据网格:Nom-版本-Editeur
我使用datatrigger(XAML),并在代码中更改了变量(True / False)。
我的问题:当我更改变量(例如EditeurGroupe = True)时,我的图标列更改为列。我只想更改一列。
谢谢您的帮助
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Height" Value="30"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="BtnGroup" Grid.Column="0" Background="Transparent" BorderBrush="Transparent" HorizontalAlignment="Left" Height="16" Width="16" Click="BtnGrouper_Click">
<StackPanel>
<Image Stretch="Fill">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="Images/GrouperColonne.png"/>
<Style.Triggers>
<!--<DataTrigger Binding="{Binding MainWindow.EditeurGroupe, Mode=TwoWay}" Value="False">-->
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=EditeurGroupe}" Value="False">
<Setter Property="Source" Value="Images/GrouperColonne.png"/>
</DataTrigger>
<!--<DataTrigger Binding="{Binding MainWindow.EditeurGroupe, Mode=TwoWay}" Value="True">-->
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=EditeurGroupe}" Value="True">
<Setter Property="Source" Value="Images/SupprimerGrouperColonne.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</StackPanel>
</Button>
<TextBlock Grid.Column="1" Text="{Binding}"/>
<Button Grid.Column="2" Background="Transparent" BorderBrush="Transparent" HorizontalAlignment="Right" Height="16" Width="16" Click="BtnFilter_Click">
<StackPanel>
<Image Name="ImgFiltre" Stretch="Fill">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="Images/Filtre.png"/>
<Style.Triggers>
<!--<DataTrigger Binding="{Binding EditeurFiltre}" Value="True">-->
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}, Path=DataContext.EditeurFiltre}" Value="True">
<Setter Property="Source" Value="Images/FiltreAjouter.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
我的活动按钮:
Private Sub BtnGrouper_Click(sender As Object, e As RoutedEventArgs) Handles BtnGrouper.Click
Try
Dim Colonne As DataGridColumnHeader = FindParentColumn(sender)
MessageBox.Show("Nom de la colonne : " & Colonne.Column.Header)
Dim ButtonGroup As Button = sender
LogicielVueCollection = CollectionViewSource.GetDefaultView(Me.DataGridLogiciel.ItemsSource)
LogicielVueCollection.GroupDescriptions.Add(New PropertyGroupDescription(Colonne.Column.Header))
Me.ListeGroupeColonne.Items.Clear()
Dim DernierGroupe As TreeViewItem = Nothing
For Each Groupe As PropertyGroupDescription In LogicielVueCollection.GroupDescriptions
Dim NouveauGroupe As New TreeViewItem
NouveauGroupe.Header = Groupe.PropertyName
NouveauGroupe.IsExpanded = True
If Me.ListeGroupeColonne.Items.Count = 0 Then
Me.ListeGroupeColonne.Items.Add(NouveauGroupe)
Else
DernierGroupe.Items.Add(NouveauGroupe)
End If
DernierGroupe = NouveauGroupe
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub