Re: [問題] Android Xamarin DataGrid update
讓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


: 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>
: 謝謝
--
推
07/28 16:53,
07/28 16:53
→
07/28 16:55,
07/28 16:55
→
07/28 16:56,
07/28 16:56
推
07/28 16:57,
07/28 16:57
推
07/28 16:58,
07/28 16:58
推
07/28 16:59,
07/28 16:59
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.31.13 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1623719945.A.D91.html
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章