Created
November 14, 2012 06:59
-
-
Save erikdietrich/4070742 to your computer and use it in GitHub Desktop.
View model for the main window, including combo box item logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Controls; | |
namespace WpfScratchpad | |
{ | |
public class MainWindowViewModel | |
{ | |
private readonly List<string> _actualOptions = new List<string>() { "Option 1", "Option 2", "Option 3" }; | |
private readonly string _initialText; | |
public ObservableCollection<string> Options { get; private set; } | |
/// <summary> | |
/// Initializes a new instance of the MainWindowViewModel class. | |
/// </summary> | |
public MainWindowViewModel(string initialText) | |
{ | |
_initialText = initialText; | |
Options = new ObservableCollection<string>(); | |
InitializeComboItems(); | |
} | |
public void RemoveSelect() | |
{ | |
if (Options.Count > _actualOptions.Count) | |
{ | |
Options.Clear(); | |
AddOptions(); | |
} | |
} | |
private void InitializeComboItems() | |
{ | |
Options.Add(_initialText); | |
AddOptions(); | |
} | |
private void AddOptions() | |
{ | |
_actualOptions.ForEach(opt => Options.Add(opt)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment