值更改后触发的复选框事件

编程入门 行业动态 更新时间:2024-10-27 03:34:58
本文介绍了值更改后触发的复选框事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建我的第一个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.

解决了!

更多推荐

值更改后触发的复选框事件

本文发布于:2023-11-04 01:25:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!