WPF DataGrid 使用 [xmal]

本文详细介绍了WPF DataGrid的使用,包括如何通过XAML进行配置,展示了DataGrid的基本功能,如数据绑定、列定义、排序、分页等,并提供了实例代码帮助理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<pu:WindowX x:Class="GloveBoxInsp.IoPortViewer"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:pu="clr-namespace:Panuon.UI.Silver;assembly=Panuon.UI.Silver"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:GloveBoxInsp"
        mc:Ignorable="d"
        Title="IoPortViewer" Height="475.035" Width="428.234" WindowStyle="None" Loaded="WindowX_Loaded" Closing="WindowX_Closing" Closed="WindowX_Closed">
    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="50"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" x:Name="lb_IoDevice">连接IO设备:</Label>
            <ComboBox Grid.Row="0" Grid.Column="1" x:Name="comboBoxDigitalIo"  Margin="0" VerticalAlignment="Top" SelectionChanged="comboBoxDigitalIo_SelectionChanged"/>
            <Button Grid.Row="0" Grid.Column="2" x:Name="btnClose" Content="关闭窗口" Width="75" Click="btnClose_Click"/>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <GroupBox x:Name="inportTable" Grid.Column="0" Header="输入信号">
                <DataGrid x:Name="inportDataGrid" ItemsSource="{Binding}"
                              BorderBrush="LightGray"
                              BorderThickness="1"
                              CanUserAddRows="False">
                    <pu:DataGridHelper.AutoGenerateCheckBoxStyle>
                        <Style TargetType="CheckBox"
                                   BasedOn="{StaticResource {x:Type CheckBox}}">
                            <Setter Property="pu:CheckBoxHelper.CheckBoxStyle"
                                        Value="Switch" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=(pu:CheckBoxHelper.CheckBoxStyle),RelativeSource={RelativeSource Self}}"
                                                 Value="Switch">
                                    <Setter Property="pu:CheckBoxHelper.CheckedBackground"
                                                Value="#72C81F" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </pu:DataGridHelper.AutoGenerateCheckBoxStyle>
                </DataGrid>
            </GroupBox>
            <GroupBox  Grid.Column="1" Header="输出信号">
                <DataGrid x:Name="outportDataGrid"  ItemsSource="{Binding}"
                              BorderBrush="LightGray"
                              BorderThickness="1"
                                
                                
                        
                          
                              >
                    <pu:DataGridHelper.AutoGenerateCheckBoxStyle>
                        <Style  TargetType="CheckBox"
                                   BasedOn="{StaticResource {x:Type CheckBox}}">
                            <Setter Property="pu:CheckBoxHelper.CheckBoxStyle"
                                        Value="Switch" />
                    
                            <Style.Triggers>
                                    
                                    <DataTrigger Binding="{Binding Path=(pu:CheckBoxHelper.CheckBoxStyle),RelativeSource={RelativeSource Self}}"
                                                 Value="Switch">
                                    <Setter Property="pu:CheckBoxHelper.CheckedBackground"
                                                Value="Red" />
                                </DataTrigger>
                            </Style.Triggers>
                            
                        </Style>
                    </pu:DataGridHelper.AutoGenerateCheckBoxStyle>
                </DataGrid>
            </GroupBox>
        </Grid>
        
        

    </Grid>
</pu:WindowX>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值