Re: [問題] Android Xamarin DataGrid update
有將DataGrid ItemSource屬性綁在ObservableCollection
但是還是不會動,請問是否有寫錯,程式碼如下:
view model :
public class ShipVM : ViewModelBase
{
private ObservableCollection<ShipModel> shipList;
public ObservableCollection<ShipModel> ShipList
{
get => shipList;
set
{
shipList = value;
OnPropertyChanged("B");
}
}
}
xaml.cs :
<dg:DataGrid x:Name="grid" ItemsSource="{Binding ShipList>
<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" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn Title="E" PropertyName="E" Width="1*"/>
</dg:DataGrid.Columns>
</dg:DataGrid>
※ 引述《e23882 (呆呆要不要買降有)》之銘言:
: 讓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>
: : 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.73.9 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1624364401.A.9CA.html
→
07/11 04:21,
3年前
, 1F
07/11 04:21, 1F
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章