【发布时间】:2020-05-22 19:12:30
【问题描述】:
我的项目中有多个选择器,由于某种原因,只有一个选择器没有绑定。我已经搞砸了两天了,无论我是否更改为可观察的集合或字符串列表,它仍然无法正常工作。
这里是 xaml
<Picker x:Name="PickerMarket" Title="Market" ClassId="PickerMarket"
ItemsSource="{Binding TestList}"
ItemDisplayBinding="{Binding ShortDesc}"
SelectedItem="{Binding ShortDesc}"
Grid.Row="0" Grid.Column="1" >
</Picker>
这是视图模型
class VamiMarketViewModel: INotifyPropertyChanged
{
private List<Performance> _testList;
public List<Performance> TestList
{
get { return _testList; }
set
{
{
_testList = value;
NotifyPropertyChanged();
}
}
}
private string _shortDesc;
public string ShortDesc
{
get { return _shortDesc; }
set
{
{
_shortDesc = value;
NotifyPropertyChanged();
}
}
}
public class Performance
{
public int PerformanceDailyTableId { get; set; }
public DateTime Filedate { get; set; }
public string Office { get; set; }
public string Account { get; set; }
public decimal TradeLevel { get; set; }
public decimal BeginningEquity { get; set; }
public decimal fxPL { get; set; }
public decimal CashActivity { get; set; }
public decimal CashActivityNonPl { get; set; }
public decimal TBills { get; set; }
public decimal OTEChange { get; set; }
public decimal Realized { get; set; }
public decimal Commission { get; set; }
public decimal ClearingFees { get; set; }
public decimal ExchangeFees { get; set; }
public decimal NFAFees { get; set; }
public decimal BrokerageFees { get; set; }
public decimal TransactionFees { get; set; }
public decimal NetPerformance { get; set; }
public decimal EndingEquity { get; set; }
public decimal DailyROR { get; set; }
public decimal Vami { get; set; }
public decimal ADMstmtNLVchange { get; set; }
public decimal ManualAdjustment { get; set; }
public decimal DoubleCheck { get; set; }
public string AccountNumber { get; set; }
public string Sector { get; set; }
public string ShortDesc { get; set; }
}
在仅为测试目的创建视图模型时,我试图像这样填充列表
Performance p1 = new Performance();
p1.ShortDesc = "user";
TestList.Add(p1);
Performance p2 = new Performance();
p2.ShortDesc = "stephen";
TestList.Add(p2);
【问题讨论】:
-
try
ItemDisplayBinding="ShortDesc"-ItemDisplayBinding是用于显示的属性名称,而不是实际的绑定表达式 -
它不允许我这样做... xaml 中的语法错误?
-
我刚刚仔细检查了文档,显然我的记忆有问题 - 该属性确实需要一个绑定表达式
-
感谢您检查...还有什么其他想法为什么它不起作用?
-
刚刚确认它与我的异步下载数据有关......然后对该方法所做的任何事情都不会反映在 UI 中。这正常吗?
标签: xamarin.forms data-binding picker