bovender framework
C# framework that implements MVVM and more
EnumViewModel.cs
1 /* EnumViewModel.cs
2  * part of Daniel's XL Toolbox NG
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 
23 namespace Bovender.Mvvm.ViewModels
24 {
31  public sealed class EnumViewModel<T> : ViewModelBase
32  where T : struct, IConvertible
33  {
34  #region Public properties
35 
36  public T Value { get; private set; }
37  public string Description
38  {
39  get
40  {
41  return _description;
42  }
43  set
44  {
45  _description = value;
46  OnPropertyChanged("Description");
47  }
48  }
49 
50  public string ToolTip
51  {
52  get
53  {
54  return _toolTip;
55  }
56  set
57  {
58  _toolTip = value;
59  OnPropertyChanged("ToolTip");
60  }
61  }
62 
63  public bool IsEnabled
64  {
65  get
66  {
67  return _isEnabled;
68  }
69  set
70  {
71  _isEnabled = value;
72  OnPropertyChanged("IsEnabled");
73  }
74  }
75 
76  #endregion
77 
78  #region Constructors
79 
80  internal EnumViewModel(T value)
81  : base()
82  {
83  Value = value;
84  _isEnabled = true;
85  }
86 
87  internal EnumViewModel(T value, string description)
88  : this(value)
89  {
90  _description = description;
91  }
92 
93  internal EnumViewModel(T value, string description, string toolTip)
94  : this(value, description)
95  {
96  _toolTip = toolTip;
97  }
98 
99  internal EnumViewModel(T value, string description, string toolTip,
100  bool isEnabled)
101  : this(value, description, toolTip)
102  {
103  _isEnabled = isEnabled;
104  }
105 
106  internal EnumViewModel(T value, string description, bool isEnabled)
107  : this(value, description)
108  {
109  _isEnabled = isEnabled;
110  }
111 
112  #endregion
113 
114  #region Overrides
115 
116  public override string DisplayString
117  {
118  get
119  {
120  if (String.IsNullOrEmpty(Description))
121  {
122  return Value.ToString();
123  }
124  else
125  {
126  return Description;
127  }
128  }
129  }
130 
131  public override string ToString()
132  {
133  return DisplayString;
134  }
135 
136  #endregion
137 
138  #region Implementation of ViewModelBase
139 
140  public override object RevealModelObject()
141  {
142  return Value;
143  }
144 
145  #endregion
146 
147  #region Private fields
148 
149  private string _description;
150  private string _toolTip;
151  private bool _isEnabled;
152 
153  #endregion
154  }
155 }
override object RevealModelObject()
Returns the model object that this view model wraps or null if there is no wrapped model object...
View model for enum members.