[英]Xamarin Forms devexpress grid - access cell
我正在將Xamarin Forms與devexpress網格一起使用,該網格包含多行。 我希望能夠獲取所選行/單元格的值。 我該如何實現?
<ScrollView>
<dxGrid:GridControl
x:Name="grid"
ItemsSource="{Binding materials}"
AutoFilterPanelVisibility="true"
IsReadOnly="true"
SortMode="Multiple">
<dxGrid:GridControl.Columns>
<dxGrid:TextColumn
FieldName="id"
Caption = "ID"
AutoFilterCondition="Contains"/>
<dxGrid:TextColumn
FieldName="description"
Caption = "Material"
AutoFilterCondition="Contains"/>
</dxGrid:GridControl.Columns>
</dxGrid:GridControl>
</ScrollView>
material是一個簡單的List,其中Material是一個簡單的示例類,其中包含兩個字符串屬性(id,description)。
如您在文檔中所見,可以綁定屬性SelectedRowHandle
來恢復選定的行:
當最終用戶點擊網格中的數據行時,該行將被選中。 使用SelectedRowHandle屬性獲取或設置網格中當前選定的行。 SelectedDataObject屬性返回一個對象,該對象指定網格中所選行所對應的數據源記錄。 更改網格的選擇后,發生SelectionChanged事件。
希望對您有所幫助。
我自己想通了:
<ScrollView>
<dxGrid:GridControl
x:Name="grid"
ItemsSource="{Binding materials}"
AutoFilterPanelVisibility="true"
IsReadOnly="true"
SortMode="Multiple"
SelectedRowHandle="{Binding selectedRow, Mode=TwoWay}"
SelectedDataObject="{Binding selectedRowObject, Mode=TwoWay}">
<dxGrid:GridControl.Columns>
<dxGrid:TextColumn
FieldName="description"
Caption = "Material"
AutoFilterCondition="Contains"/>
</dxGrid:GridControl.Columns>
</dxGrid:GridControl>
</ScrollView>
和視圖模型:
private int SelectedRow;
public int selectedRow
{
set
{
if(SelectedRow != value)
{
SelectedRow = value;
if(PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("selectedRow"));
}
}
}
get
{
return SelectedRow;
}
}
private Object SelectedRowObject;
public Object selectedRowObject
{
set
{
if (SelectedRowObject != value)
{
SelectedRowObject = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("selectedRowObject"));
PropertyChanged(this, new PropertyChangedEventArgs("selectedRowDescription"));
}
}
}
get
{
return SelectedRowObject;
}
}
private String SelectedRowDescription;
public String selectedRowDescription
{
get
{
if(SelectedRowObject != null && SelectedRowObject is Material)
{
Material mat = (Material)SelectedRowObject;
return mat.description;
} else
{
return "-";
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.