提问者:小点点

WPF datagird复选框-单击选择,选中/取消选中时激发事件


我有一个WPF(Modern-UI)DataGird:

<DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserResizeRows="False" CanUserAddRows="False" Margin="1,1,1,0" HorizontalAlignment="Left" VerticalAlignment="Top" DockPanel.Dock="Top" Visibility="Hidden" BeginningEdit="DG1_BeginningEdit" >
            <DataGrid.Columns>
                <mui:DataGridCheckBoxColumn Header="Auswahl" Binding="{Binding IsSelected,UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" />
                <mui:DataGridTextColumn Header="Name"  Binding="{Binding FolderName}"/>
                <mui:DataGridTextColumn Header="Größe" Binding="{Binding FolderSize}"/>
                <mui:DataGridTextColumn Header="Pfad" Binding="{Binding FolderPath}" />
                <mui:DataGridTextColumn Header="Pfad" Binding="{Binding FolderSizeBytes}" Visibility="Hidden" />
            </DataGrid.Columns>
        </DataGrid>

如何为复选框设置“一次单击选择”(类似WinForms的CheckOnClick)?

当复选框被选中/取消选中时,我如何激发事件? 我尝试了BeginningEdit,CellEditEnding,CurrentCellChanged,还尝试了。updateLayout(),。commitEdit()等。我只想计数FolderSizeBytes,并在选中复选框时更新它。

对于这个任务,有没有更好的GUI选项?


共1个答案

匿名用户

您可以将DataGridCheckBoxColumn替换为DataGridTemplateColumn:

<DataGridTemplateColumn Header="Auswahl" IsReadOnly="False">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>