Reputation: 33
I am trying to create a ordering solution. I have a collectionView that is bound to a List. The datatemplate of the collectionview is created at runtime. Inside the datatemplate i have a Entry. I make a call to a webservice and i get a Item.
Before I insert the Item inside the list i make a linq search and if the Item does not exist in the list I insert it to it.
So far so good.
But when the linq search returns a line, i want somehow to focus at the entry, so i can change the text (it as a qty field) of it.
My code as simple as i can make it:
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;
});
}
Upvotes: 0
Views: 821
Reputation: 1666
I don't see the INotifyPropertyChanged implementation to your class
public class IteLine : INotifyPropertyChanged
{
private double _qty;
public string Qty
{
get {return _qty;}
set
{
_qty= value;
OnPropertyChanged("Qty");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Now, if you find the index where you want to change it. You can do it like this
IteLines[linkqIndex].Qty = 5;
Upvotes: 1