我的wpf上有一个数据网格,里面创建了拖车按钮 并且我只想在鼠标悬停在数据网格上时显示 我想让我做到这一点我需要在这个网格的行上添加一个事件来鼠标悬停 bellow是我的DataGrid代码
<DataGrid Grid.Row="1" GridLinesVisibility="None" AlternationCount="2" HorizontalAlignment="Left" Height="auto" VerticalAlignment="Stretch" BorderThickness="0" Name="dgUsers" ItemsSource="{Binding NotasSincronizadas}" Margin="0 0 0 0"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
>
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="local:WaterMarkTextHelperl.HasText" Value="False"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
</MultiTrigger>
</MultiTrigger>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridCheckBoxColumn x:Name="col0" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}">
<DataGridCheckBoxColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Name="chkSelectAll" ></CheckBox>
</DataTemplate>
</DataGridCheckBoxColumn.HeaderTemplate>
</DataGridCheckBoxColumn>
<DataGridTemplateColumn Width="100" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<Label Width="100" HorizontalContentAlignment="Center">NÚMERO</Label>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<Grid Width="100">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"></ColumnDefinition>
<ColumnDefinition Width="50*" x:Name="columBtAuto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding Path=CNS_NUMERO_NOTA}"></Label>
<Grid Grid.Column="1" Width="50" Height="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button ToolTip="Manifestar" Grid.Column="0" Tag="{Binding Path=CNS_NUMERO_NOTA}" Style="{StaticResource buttonTransparent}">
<fa:ImageAwesome Icon="File" Width="12"></fa:ImageAwesome>
</Button>
<Button ToolTip="Imprimir" Grid.Column="1" Tag="{Binding Path=CNS_NUMERO_NOTA}" Style="{StaticResource buttonTransparent}">
<fa:ImageAwesome Icon="Print" Width="12"></fa:ImageAwesome>
</Button>
</Grid>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn x:Name="br_numero" Header="NÚMERO" Width="100" Binding="{Binding CNS_NUMERO_NOTA}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}" />
<DataGridTextColumn x:Name="br_serie" Header="SERIE" Width="80" Binding="{Binding CNS_SERIE}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}" ></DataGridTextColumn>
<DataGridTextColumn x:Name="br_data_de_emissao" Header="DATA" Width="120" Binding ="{Binding Path=CNS_DATA_EMISSAO, StringFormat=dd-MM-yyyy}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}"></DataGridTextColumn>
<DataGridTextColumn x:Name="br_cnpj" Width="150" Header="CNPJ" Binding ="{Binding Path=CNS_CNPJ, StringFormat={}{0:##\###\###\/####-##}}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}" />
<DataGridTextColumn x:Name="br_empresa_nome" Width="400" Header="EMPRESA" Binding ="{Binding CNS_NOME_FANTASIA}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}" />
<DataGridTextColumn x:Name="br_valor" Width="90" Header="VALOR" Binding ="{Binding Path=CNS_VALOR_TOTAL, StringFormat={}{0:#.##}}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}" />
<DataGridTextColumn x:Name="br_chave_de_acesso" Width="350" Header="CHAVE DE ACESSO" Binding ="{Binding Path=CNS_VALOR_TOTAL, StringFormat={}{0:#.##}}" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}" />
</DataGrid.Columns>
</DataGrid>
有没有办法将这些事件放在行中?
我正在尝试使用此代码
<Style TargetType="{x:Type DataGridRow}">
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="local:HideShow.Somefunction" Value="False"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
</MultiTrigger>
</Style>
但它也不起作用
答案 0 :(得分:1)
我终于意识到该怎么做了 Jus需要使用EventSetter而不是触发器
如下面的代码
<EventSetter Event="MouseEnter" Handler="Row_MouseEnter"/>