|
| 1 | +using ActiproSoftware.Windows.Controls.Bars; |
| 2 | +using ActiproSoftware.Windows.Controls.Bars.Mvvm; |
| 3 | +using System.Collections; |
| 4 | + |
| 5 | +namespace ActiproSoftware.ProductSamples.BarsSamples.QuickStart.ComboBoxAndEditors { |
| 6 | + |
| 7 | + /// <summary> |
| 8 | + /// Represents a view model for an auto-complete box control within a bar control. |
| 9 | + /// </summary> |
| 10 | + public class AutoCompleteBoxViewModel : BarKeyedObjectViewModelBase { |
| 11 | + |
| 12 | + private string description; |
| 13 | + private bool hasClearButton; |
| 14 | + private IEnumerable itemsSource; |
| 15 | + private string itemsSourceDisplayMemberPath; |
| 16 | + private string itemsSourceTextMemberPath; |
| 17 | + private string label; |
| 18 | + private string popupHeader; |
| 19 | + private double requestedWidth = 110.0; |
| 20 | + private object selectedItem; |
| 21 | + |
| 22 | + ///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | + // OBJECT |
| 24 | + ///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Initializes a new instance of the class. |
| 28 | + /// </summary> |
| 29 | + public AutoCompleteBoxViewModel() // Parameterless constructor required for XAML support |
| 30 | + : this(key: null) { } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Initializes a new instance of the class with the specified key. The label is auto-generated. |
| 34 | + /// </summary> |
| 35 | + /// <param name="key">A string that uniquely identifies the control.</param> |
| 36 | + public AutoCompleteBoxViewModel(string key) |
| 37 | + : this(key, label: null) { } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Initializes a new instance of the class with the specified key and label. |
| 41 | + /// </summary> |
| 42 | + /// <param name="key">A string that uniquely identifies the control.</param> |
| 43 | + /// <param name="label">The text label to display, which is auto-generated from the <paramref name="key"/> if <c>null</c>.</param> |
| 44 | + public AutoCompleteBoxViewModel(string key, string label) |
| 45 | + : base(key) { |
| 46 | + |
| 47 | + this.label = label ?? BarControlService.LabelGenerator.FromKey(key); |
| 48 | + } |
| 49 | + |
| 50 | + ///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | + // PUBLIC PROCEDURES |
| 52 | + ///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Gets or sets the text label to display. |
| 56 | + /// </summary> |
| 57 | + /// <value>The text label to display.</value> |
| 58 | + public string Label { |
| 59 | + get => label; |
| 60 | + set { |
| 61 | + if (label != value) { |
| 62 | + label = value; |
| 63 | + this.NotifyPropertyChanged(nameof(Label)); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Gets or sets the text description to display in screen tips. |
| 70 | + /// </summary> |
| 71 | + /// <value>The text description to display in screen tips.</value> |
| 72 | + public string Description { |
| 73 | + get => description; |
| 74 | + set { |
| 75 | + if (description != value) { |
| 76 | + description = value; |
| 77 | + this.NotifyPropertyChanged(nameof(Description)); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Gets or sets if the clear button is displayed. |
| 84 | + /// </summary> |
| 85 | + /// <value><c>true</c> if the clear button is displayed; otherwise, <c>false</c>.</value> |
| 86 | + public bool HasClearButton { |
| 87 | + get => hasClearButton; |
| 88 | + set { |
| 89 | + if (hasClearButton != value) { |
| 90 | + hasClearButton = value; |
| 91 | + this.NotifyPropertyChanged(nameof(HasClearButton)); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Gets or sets the source of items to be auto-completed. |
| 98 | + /// </summary> |
| 99 | + /// <value>The items source.</value> |
| 100 | + public IEnumerable ItemsSource { |
| 101 | + get => itemsSource; |
| 102 | + set { |
| 103 | + if (itemsSource != value) { |
| 104 | + itemsSource = value; |
| 105 | + this.NotifyPropertyChanged(nameof(ItemsSource)); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Gets or sets a path to a value on the source object to serve as the visual representation of the object. |
| 112 | + /// </summary> |
| 113 | + /// <value>A path to a value on the source object to serve as the visual representation of the object.</value> |
| 114 | + public string ItemsSourceDisplayMemberPath { |
| 115 | + get => itemsSourceDisplayMemberPath; |
| 116 | + set { |
| 117 | + if (itemsSourceDisplayMemberPath != value) { |
| 118 | + itemsSourceDisplayMemberPath = value; |
| 119 | + this.NotifyPropertyChanged(nameof(ItemsSourceDisplayMemberPath)); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + /// <summary> |
| 125 | + /// Gets or sets the property path that is used to get the value for display in the text box portion of the control, when an item is selected. |
| 126 | + /// </summary> |
| 127 | + /// <value>The property path that is used to get the value for display in the text box portion of the control, when an item is selected.</value> |
| 128 | + public string ItemsSourceTextMemberPath { |
| 129 | + get => itemsSourceTextMemberPath; |
| 130 | + set { |
| 131 | + if (itemsSourceTextMemberPath != value) { |
| 132 | + itemsSourceTextMemberPath = value; |
| 133 | + this.NotifyPropertyChanged(nameof(ItemsSourceTextMemberPath)); |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + /// <summary> |
| 139 | + /// Gets or sets the header to be displayed in the popup. |
| 140 | + /// </summary> |
| 141 | + /// <value>The header to be displayed in the popup.</value> |
| 142 | + public string PopupHeader { |
| 143 | + get => popupHeader; |
| 144 | + set { |
| 145 | + if (popupHeader != value) { |
| 146 | + popupHeader = value; |
| 147 | + this.NotifyPropertyChanged(nameof(PopupHeader)); |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + /// <summary> |
| 153 | + /// Gets or sets the requested width of the control. |
| 154 | + /// </summary> |
| 155 | + /// <value> |
| 156 | + /// The requested width of the control. |
| 157 | + /// The default value is <c>110</c>. |
| 158 | + /// </value> |
| 159 | + public double RequestedWidth { |
| 160 | + get => requestedWidth; |
| 161 | + set { |
| 162 | + if (requestedWidth != value) { |
| 163 | + requestedWidth = value; |
| 164 | + this.NotifyPropertyChanged(nameof(RequestedWidth)); |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + /// <summary> |
| 170 | + /// Gets or sets the currently selected item. |
| 171 | + /// </summary> |
| 172 | + /// <value>The currently selected item.</value> |
| 173 | + public object SelectedItem { |
| 174 | + get => selectedItem; |
| 175 | + set { |
| 176 | + if (selectedItem != value) { |
| 177 | + selectedItem = value; |
| 178 | + this.NotifyPropertyChanged(nameof(SelectedItem)); |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + } |
| 184 | + |
| 185 | +} |
0 commit comments