Advertisement
parabola949

ComboBox WPF with 10 item history

Dec 4th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. //Will redo in MVVM later, but the quick and dirty method
  2. //Will also add autocomplete later
  3. //In View.cs:
  4. public NovellDesktopView()
  5.         {
  6.             InitializeComponent();
  7.             NovellHistory.ItemsSource = Settings.NovellHistory;
  8.         }
  9.  
  10.         private void Run_Click(object sender, RoutedEventArgs e)
  11.         {
  12.             var history = Settings.NovellHistory;
  13.             Settings.NovellHistory = AddHistoryItem(history, NovellHistory.Text);
  14.         }
  15.  
  16.         private List<string> AddHistoryItem(List<string> input, string item)
  17.         {
  18.             var output = new List<string>();
  19.             output.Add(item);
  20.             output.AddRange(input);
  21.             if (output.Count >= 10)
  22.                 output.RemoveAt(9);
  23.             return output;
  24.         }
  25.  
  26. //In Settings.Designer.cs
  27.         [global::System.Configuration.UserScopedSettingAttribute()]
  28.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  29.         [global::System.Configuration.DefaultSettingValueAttribute("")]
  30.         public System.Collections.Generic.List<string> NovellHistory
  31.         {
  32.             get {
  33.                 return ((System.Collections.Generic.List<string>)(this["NovellHistory"]));
  34.             }
  35.             set {
  36.                 this["NovellHistory"] = value;
  37.             }
  38.         }
  39.  
  40. //In my Settings.cs class (because I hate typing out Properties.Settings.Default.SomeSetting)
  41.         public static List<string> NovellHistory
  42.         {
  43.             get { return Properties.Settings.Default.NovellHistory; }
  44.             set { Properties.Settings.Default.NovellHistory = value; Properties.Settings.Default.Save(); }
  45.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement