值更改后触发的复选框事件 [英] Checkbox event that fires AFTER the value has changed

查看:111
本文介绍了值更改后触发的复选框事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建我的第一个wpf应用程序.这时我需要一个事件,该事件在复选框的值更改后触发,因此选中和未选中的对象不在画面内:-(

I'm creating my very first wpf application. At this moment I need an event that fires AFTER the value of a checkbox has changed, so checked and unchecked are out of the picture :-(

我有一个数据网格,绑定到一个可观察的集合.在此datagrid中,我有一列带有复选框(绑定到observ.col.中的属性). 表单上的文本框显示总值",即所有选中项的值之和.因此,当一个复选框被选中/取消选中时,我需要重新计算总值.为此,我遍历了观察项.上校但是,当我附加事件选中"和未选中"时.首先计算总价值.然后更改检查值.

I have a datagrid, binded to an observable collection. In this datagrid I have a column with checkboxes (binded to a property in the observ. col.). A textbox on the form shows the 'total value' that is the sum of the values of all checked items. So when a checkbox is checked/unchecked I need to recalculate the total value. To do this I loop over the items of the observ. col. However, when I attach the events 'checked' and 'unchecked'. The total value gets calculated first. Then the check-value is changed.

有没有一种方法可以更改检查值,然后触发一个事件?

Is there a way to have the check value changed and after that fire an event?

Thx,

Jan

<DataGrid AutoGenerateColumns="False" Height="305" Margin="105,137,0,0" Name="GrdReceivings" VerticalAlignment="Top" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" ItemsSource="{Binding}" HorizontalAlignment="Left" Width="850" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" SelectedCellsChanged="GrdReceivings_SelectedCellsChanged" MouseDoubleClick="GrdReceivings_MouseDoubleClick" IsEnabled="True">
    <DataGrid.Columns>
            <DataGridCheckBoxColumn MinWidth="40" Binding="{Binding Path=Selected}" >
                <DataGridCheckBoxColumn.CellStyle>
                    <Style>
                        <EventSetter Event="CheckBox.Checked" Handler="OnCheck"/>
                        <EventSetter Event="CheckBox.Unchecked" Handler="OnUncheck"/>
                    </Style>
                </DataGridCheckBoxColumn.CellStyle>
            </DataGridCheckBoxColumn>
...

推荐答案

谢里登&克莱门斯(Clemens),它成功了.制定好的答案:

Thx to Sheridan & Clemens, it did the trick. To formulate the good answer:

<DataGrid AutoGenerateColumns="False" Height="305" Margin="105,137,0,0" Name="GrdReceivings" VerticalAlignment="Top" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" ItemsSource="{Binding}" HorizontalAlignment="Left" Width="850" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" SelectedCellsChanged="GrdReceivings_SelectedCellsChanged" MouseDoubleClick="GrdReceivings_MouseDoubleClick" IsEnabled="True">
    <DataGrid.Columns>
            <DataGridCheckBoxColumn MinWidth="40" Binding="{Binding Path=Selected, UpdateSourceTrigger=PropertyChanged}" />

然后在可观察的集合中的setter上计算值.

then, in the observable collection, on the setter, calculate the value.

解决了!

这篇关于值更改后触发的复选框事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆