Skip to content

Instantly share code, notes, and snippets.

@erikdietrich
Created November 14, 2012 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikdietrich/4070742 to your computer and use it in GitHub Desktop.
Save erikdietrich/4070742 to your computer and use it in GitHub Desktop.
View model for the main window, including combo box item logic
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