You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when I choose this option and close the app,the selectedItem will be set null,how come?
ViewModel
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Avalonia.ComboBoxBinding.ViewModels;
public partial class MainViewModel : ObservableObject
{
[ObservableProperty] private Person? _selectedPerson;
public ObservableCollection<Person> People { get; set; } =
[
new()
{
Name = "John",
Age = 25,
},
new()
{
Name = "Jane",
Age = 25,
},
new()
{
Name = "Mary",
Age = 25,
}
];
public ObservableCollection<Teacher> Teachers { get; set; } =
[
new()
{
Name = "Aohn",
Age = 25,
},
new()
{
Name = "Aane",
Age = 25,
},
new()
{
Name = "Aary",
Age = 25,
}
];
}
public partial class Teacher : ObservableObject
{
[ObservableProperty] private string _name = string.Empty;
[ObservableProperty] private int _age;
}
public partial class Person : ObservableObject
{
[ObservableProperty] private string _name = string.Empty;
[ObservableProperty] private int _age;
private Teacher? _teacher;
public Teacher? Teacher
{
get => _teacher;
set
{
if (value is null) Console.WriteLine("value is null");
SetProperty(ref _teacher, value);
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
when I choose this option and close the app,the selectedItem will be set null,how come?
ViewModel
View
Beta Was this translation helpful? Give feedback.
All reactions