数据绑定计算字段

编程入门 行业动态 更新时间:2024-10-24 14:24:23
本文介绍了数据绑定计算字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我运行到哪里我想一个DataGrid的DataTextColumn绑定到计算字段的小问题。

I'm running into a small problem where I'm trying to bind a DataTextColumn of a DataGrid to a Calculated Field.

WPF

<DataGrid ItemsSource="{Binding Path=CurrentRoster, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" AlternatingRowBackground="Gainsboro" AlternationCount="2"> <DataGrid.Columns> <DataGridComboBoxColumn Header="Student Enrolled" ItemsSource="{Binding Source={StaticResource AvailableStudents}}" SelectedItemBinding="{Binding Path=Student}"> </DataGridComboBoxColumn> <DataGridTextColumn Header="Registration" Binding="{Binding Path=RegistrationCosts, StringFormat='{}{0:C}'}"/> <DataGridTextColumn Header="Lodging" Binding="{Binding Path=LodgingCosts, StringFormat='{}{0:C}'}"/> <DataGridTextColumn Header="Travel" Binding="{Binding Path=TravelCosts, StringFormat='{}{0:C}'}"/> <DataGridTextColumn Header="Dining" Binding="{Binding Path=DiningCosts, StringFormat='{}{0:C}'}"/> <DataGridTextColumn Header="Total Costs" IsReadOnly="True" Binding="{Binding Path=TotalCosts, StringFormat='{}{0:C}'}"/> </DataGrid.Columns>

在哪里学生是一个小的添加实体对象。 TotalCosts是不是对数据库表的字段,所以我创建了一个局部类此。

Where Student is a Entity object with one small addition. TotalCosts isn't a field on the db tables, so I created a partial class for this.

public partial class Student { public Decimal TotalCosts { get { return (LodgingCosts + RegistrationCosts + TravelCosts + DiningCosts); } } }

我遇到的问题是,TotalCosts是当你在其他任何领域的填不自动更新。我猜是因为它不是作为依赖属性中列出。我该如何解决这一对在没有设置属性?

The problem I'm experiencing is that TotalCosts is not automatically updating when you fill in any of the other fields. My guess it is because it is not listed as a dependency property. How do I resolve this for a property where there is no set ?

推荐答案

您可以致电 OnPropertyChanged( TotalCosts)在 TotalCosts 在于,将刷新绑定

You can call OnPropertyChanged("TotalCosts") in the setters of each property that TotalCosts depends on, it will refresh the binding

更多推荐

数据绑定计算字段

本文发布于:2023-11-27 06:56:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637053.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   绑定   数据

发布评论

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

>www.elefans.com

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