There is a ListView in my App and the ListView has a selector. I want to make the first item of this ListView to be selected as default at the very
I have used data binding to solve this,
using the following codebehind:
private List _units;
private Unit _selectedUnit;
public Unit selectedUnit{
get{
if (_selectedUnit is null){
return _units.Count > 0 ? _units[0] : null;
}else{
return _selectedUnit;
}
}
set{
if (_selectedUnit != value){
_selectedUnit = value;
OnPropertyChanged("selectedUnit");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName){
var changed = PropertyChanged;
if (changed != null){
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
and XAML