-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCarBrandViewModel.cs
46 lines (42 loc) · 1.51 KB
/
CarBrandViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace TabView_GenerateItems {
public class CarBrandViewModel : INotifyPropertyChanged {
private bool isSelected = false;
public string BrandName { get; }
public IReadOnlyList<CarModel> CarModels { get; }
// This property is used to change the appearance of a tab depending on its state.
public bool IsSelected {
get { return isSelected; }
set {
if (value == isSelected) return;
isSelected = value;
RaisePropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
public CarBrandViewModel(string brandName, IEnumerable<CarModel> carModels) {
if (String.IsNullOrEmpty(brandName)) {
this.BrandName = String.Empty;
}
else {
this.BrandName = brandName;
}
if (carModels == null) {
this.CarModels = new List<CarModel>();
}
else {
this.CarModels = carModels.ToList();
}
}
private void RaisePropertyChanged([CallerMemberName] string caller = "") {
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) {
handler.Invoke(this, new PropertyChangedEventArgs(caller));
}
}
}
}