看板 C_Sharp 關於我們 聯絡資訊
讓DataGrid Itemsource屬性綁定在ObservableCollection資料集合上 public ObservableCollection<YourDataModel> Collection { get{....}set{....} } 這樣在Collection屬性新增或是刪除的時候元件會接收到通知更新畫面 但是修改的時候不會更新畫面 所以你要讓YourDataModel繼承INotifyPropertyChanged介面,並實作方法 讓DataModel之間屬性變更時通知其他屬性 public class YourDataModel:INotifyPropertyChanged { private string _PropertyA = string.empty; public string PropertyA { set { if(_Property != value) { _PropertyA = value; OnPropertyChanged("A"); OnPropertyChanged("E"); } } } } ※ 引述《sunny10463 ( )》之銘言: : 最近在寫xamarin遇到個問題 : 圖一:https://imgur.com/4vILlbA.jpg
: 圖二:https://imgur.com/PIErXTB.jpg
: E = (B-C)*D : 圖一為一開始以MVVM架構載入,會自動計算欄位E : 但是圖二,修改欄位D(或C)欄位時,不會自動計算欄位E : 請問各位高手該用何事件? : 程式碼: : <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" : xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" : xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"> : <dg:DataGrid.Columns> : <dg:DataGridColumn Title="A" PropertyName="A" Width="1*"/> : <dg:DataGridColumn Title="B" PropertyName="B" Width="1*"/> : <dg:DataGridColumn Title="C" PropertyName="C" Width="1*" > : <dg:DataGridColumn.CellTemplate> : <DataTemplate> : <Entry Text="{Binding .}" Keyboard="Numeric" /> : </DataTemplate> : </dg:DataGridColumn.CellTemplate> : </dg:DataGridColumn> : <dg:DataGridColumn Title="D" PropertyName="D" Width="1*"> : <dg:DataGridColumn.CellTemplate> : <DataTemplate> : <Entry Text="{Binding .}" Keyboard="Numeric" : Completed="Entry_Completed"/> : </DataTemplate> : </dg:DataGridColumn.CellTemplate> : </dg:DataGridColumn> : <dg:DataGridColumn Title="E" PropertyName="E" : BindingContext="{Binding E}" Width="1*"/> : </dg:DataGrid.Columns> : </ContentPage> : 謝謝 --
psp2007 :我朋友說 ADC不要第一個死 07/28 16:53
lianngg :我朋友說 ADC不要臉皮太薄 07/28 16:55
JOGIBA :我朋友說 ADC贏要衝輸要縮 07/28 16:56
jjerry8888 :樓上抄電影賭神台詞XDDD 07/28 16:57
yang790609 :我朋友說 ADC打你打得到的 07/28 16:58
maynightdado:我朋友說我很帥 07/28 16:59
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.31.13 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1623719945.A.D91.html