【发布时间】:2021-12-14 08:24:18
【问题描述】:
我正在尝试在选择器中填充和显示 List"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"),但没有成功
感谢您的帮助!
【问题讨论】:
-
magasin 类的外观如何?
-
您好,刚刚编辑了我的代码以添加 magasin 类!
标签: c# xamarin binding dependencies picker