【发布时间】:2021-03-21 20:04:58
【问题描述】:
我正在尝试创建一个订购解决方案。 我有一个绑定到列表的 collectionView。 集合视图的数据模板是在运行时创建的。 在数据模板中,我有一个条目。 我打电话给一个网络服务,我得到了一个项目。
在将项目插入列表之前,我会进行 linq 搜索,如果列表中不存在该项目,则将其插入。 到目前为止,一切都很好。 但是当 linq 搜索返回一行时,我想以某种方式将注意力集中在条目上,这样我就可以更改它的文本(它作为一个数量字段)。
我的代码尽可能简单:
public class IteLinesViewModel : INotifyPropertyChanged
{
public ObservableCollection<IteLine> IteLines { get; set; }
}
public class IteLine : ExtendedBindableObject, INotifyPropertyChanged
{
private string _Name;
public string Name
{
get => _Name;
set => SetProperty(ref _Name, value);
}
private double _qty;
public double Qty
{
get => _qty;
set => SetProperty(ref _qty, value);
}
}
CollectionView4Lines.ItemTemplate = CreateItemTemplate();
private DataTemplate CreateItemTemplate()
{
return new DataTemplate(() =>
{
Grid OuterGrid = new Grid() { Margin = 0, Padding = 0 };
OuterGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });
OuterGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = 65 });
Label MainDisplayLabel = new Label() { TextType = TextType.Html, FontSize = 18 };
MainDisplayLabel.SetBinding(Label.TextProperty, "Name");
OuterGrid.Children.Add(MainDisplayLabel, 0, 0);
Entry qtyEntry = new Entry();
qtyEntry.SetBinding(Entry.TextProperty,"Qty")
OuterGrid.Children.Add(qtyEntry, 1, 0);
return OuterGrid;
});
}
【问题讨论】:
标签: c# xamarin xamarin.forms