<DataGrid Name="Viewer" CanUserAddRows="False"
BorderThickness="1"
BorderBrush="Gray"
GridLinesVisibility="Horizontal"
AutoGenerateColumns="False"
HorizontalAlignment="Left"
ItemsSource="{Binding AlertItems, Mode=TwoWay}"
VerticalAlignment="Top"
Height="194" Width="482"
Margin="173,87,0,0"
>
<DataGrid.Columns>
<DataGridTemplateColumn Width="60">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="告警颜色" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=" " VerticalAlignment="Center" HorizontalAlignment="Center" Background="{Binding Color}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn IsReadOnly="True" ElementStyle="{StaticResource DataGridTextCenter}" Binding="{Binding LevelDescription, Mode=OneWay}" Header="优先级"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" ElementStyle="{StaticResource DataGridTextCenter}" Binding="{Binding OperatorDescription, Mode=OneWay}" Header="比较符"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Width="50" ElementStyle="{StaticResource DataGridTextCenter}" Binding="{Binding Ratio, StringFormat=0.00}" Header="百分比"/>
<DataGridTextColumn IsReadOnly="True" ElementStyle="{StaticResource DataGridTextCenter}" Binding="{Binding Storage ,Converter={StaticResource B2SConverter}}" Width="35" Header="存储"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Width="180" ElementStyle="{StaticResource DataGridTextCenter}" Binding="{Binding AlertText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="告警内容"/>
<DataGridTemplateColumn Header="" MinWidth="70">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<Button Name="AlertLstEdit_btn" Visibility="Hidden"
BorderThickness="0"
Foreground="White" Click="AlertLstEdit_btn_Click">
<Button.Background>
<ImageBrush ImageSource="/PowerDiagram.Wpf;component/Images/Edit-icon.png" Stretch="Uniform"/>
</Button.Background>
</Button>
<Button Name="AlertLstDel_btn" Margin="5,0,0,0" Visibility="Hidden"
BorderThickness="0"
Foreground="White" Click="AlertLstDel_btn_Click">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="/PowerDiagram.Wpf;component/Images/delete_2.png"/>
</Button.Background>
</Button>
</WrapPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=IsMouseOver}" Value="true">
<Setter TargetName="AlertLstEdit_btn" Property="Visibility" Value="Visible" />
<Setter TargetName="AlertLstDel_btn" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Height" Value="30" />
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#FFFAFAFA" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#BCF2F2F2" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
WPF 触发器实现 DataGrid 显示鼠标所在行自定义操作按钮
最新推荐文章于 2024-08-02 07:45:06 发布