【发布时间】:2018-11-15 02:13:55
【问题描述】:
我有一个绑定到 ObservableCollection 对象的 Picker。这些项目是从 Web 服务(json 数据)填充的。
选择器正确显示数据,但 SelectedItem 不起作用。
这是我的 xaml 代码:
<Picker
ItemsSource="{Binding RatesTax}"
ItemDisplayBinding="{Binding Code}"
SelectedItem="{Binding SourceRate, Mode=TwoWay}">
</Picker>
RatesTax 是 RatesView 类的对象
public class RatesView
{
public string Code
{
get; set;
}
public double TaxRate
{
get; set;
}
}
这就是属性
public ObservableCollection<RatesView> RatesTax { get; set; }
这是 sourceRate 属性
private RatesView sourceRate;
和 SourceRate 属性
public RatesView SourceRate
{
set
{
if (sourceRate != value)
{
sourceRate = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SourceRate"));
}
}
get
{
return sourceRate;
}
}
我在 SourceRate 中放置了一个断点,以查看当我选择选择器的一些数据时它是否进入,但它没有进入 SourceRate 过程。我认为 SelectedItem="{Binding SourceRate} 没有按预期工作。
感谢您的宝贵时间!
【问题讨论】:
-
SelectedItem 和 ItemsSource 的类型不匹配
-
感谢您的回答!所以 SourceRate new 成为 RatesTax 对象?
标签: c# data-binding xamarin.forms binding picker