Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Will redo in MVVM later, but the quick and dirty method
- //Autocomplete with filtering added
- //Fixed issue with duplicate and empty history items
- // In View.xaml:
- <ComboBox Name="NovellHistory" HorizontalAlignment="Left" Margin="50,28,0,0" VerticalAlignment="Top" Width="200" IsEditable="True">
- <ComboBox.Style>
- <Style>
- <EventSetter Event="TextBox.TextChanged" Handler="History_TextChanged" />
- </Style>
- </ComboBox.Style>
- </ComboBox>
- // In View.cs:
- public NovellDesktopView()
- {
- InitializeComponent();
- NovellHistory.ItemsSource = Settings.NovellHistory;
- }
- private void Run_Click(object sender, RoutedEventArgs e)
- {
- var history = Settings.NovellHistory;
- Settings.NovellHistory = AddHistoryItem(history, NovellHistory.Text);
- }
- private List<string> AddHistoryItem(List<string> input, string item)
- {
- var output = new List<string>();
- if (!input.Contains(item) && item.Length > 0)
- output.Add(item);
- output.AddRange(input);
- if (output.Count >= 10)
- output.RemoveAt(9);
- return output;
- }
- private void History_TextChanged(object sender, TextChangedEventArgs e)
- {
- var box = (ComboBox)sender;
- box.ItemsSource = from entry in Settings.NovellHistory where entry.ToLower().Contains(box.Text.ToLower()) select entry;
- box.IsDropDownOpen = true;
- }
- //In Settings.Designer.cs
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public System.Collections.Generic.List<string> NovellHistory
- {
- get {
- return ((System.Collections.Generic.List<string>)(this["NovellHistory"]));
- }
- set {
- this["NovellHistory"] = value;
- }
- }
- //In my Settings.cs class (because I hate typing out Properties.Settings.Default.SomeSetting)
- public static List<string> NovellHistory
- {
- get { return Properties.Settings.Default.NovellHistory; }
- set { Properties.Settings.Default.NovellHistory = value; Properties.Settings.Default.Save(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement