我正在嘗試在選擇器中填充和顯示串列“magasin”。
magasin 類來自另一個專案,添加到我的主專案的依賴項中。
我能夠填充選擇器,但我沒有設法設定 Picker.ItemDisplayBinding = new Binding("otherProject.magasin.Name"); ,它只是為每個專案顯示 otherProject.magasin 。
這是我的代碼:
using otherProject;
public partial class fForm: ContentPage
{
public List<otherProject.magasin> listeMagasin;
public fForm()
{
BindingContext = this;
InitializeComponent();
listeMagasin = otherProject.magasin.chargerMagasins();
if (listeMagasin != null)
{
pickerMagasin.ItemsSource = listeMagasin;
pickerMagasin.ItemDisplayBinding = new
Binding("otherProject.magasin.Name");
}
}
}
還有我的 XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="mainProject.fForm">
<ContentPage.Content>
<StackLayout HorizontalOptions="FillAndExpand">
<Picker x:Name="pickerMagasin"></Picker>
</StackLayout>
</ContentPage.Content>
和magasin類
namespace otherProject
{
public class magasin
{
public string Code;
public string Name;
public magasin(string code)
{
Code = code;
}
public static List<magasin> chargerMagasins(){
//Code here}
}
}
我嘗試了 Binding("Name") 或 Binding("magasin.Name"),但沒有成功
謝謝你的幫助 !
uj5u.com熱心網友回復:
我認為這是因為 Name 和 Code 只是欄位,它們應該是一個屬性。嘗試改變 magasin 類
public string Name {get;set;}
public string Code {get;set;}
然后Binding("Name")將作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/345082.html
