You could also store the list as a delimited string in settings then use a converter.
<ComboBox ItemsSource="{Binding Default.ImportHistory,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay,Converter={StaticResource StringToListConverter},ConverterParameter=|}" IsEditable="True">
/// <summary>
/// Converts a delimited set of strings to a list and back again. The parameter defines the delimiter
/// </summary>
public class StringToListConverter : IValueConverter {
/// <summary>
/// Takes a string, returns a list seperated by {parameter}
/// </summary>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
string serializedList = (value ?? string.Empty).ToString(),
splitter = (parameter ?? string.Empty).ToString();
if(serializedList.Trim().Length == 0) {
return value;
}
return serializedList.Split(new[] { splitter }, StringSplitOptions.RemoveEmptyEntries);
}
/// <summary>
/// Takes a list, returns a string seperated by {parameter}
/// </summary>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
var items = value as IEnumerable;
var splitter = (parameter ?? string.Empty).ToString();
if(value == null || items == null) {
return value;
}
StringBuilder buffer = new StringBuilder();
foreach(var itm in items) {
buffer.Append(itm.ToString()).Append(splitter);
}
return buffer.ToString(0, splitter.Length > 0 ? buffer.Length - splitter.Length : buffer.Length);
}
}
Then when a browse button is clicked, you can add to the list:
var items = Settings.Default.ImportHistory.Split('|');
if(!items.Contains(dlgOpen.FileNames[0])) {
Settings.Default.ImportHistory += ("|" + dlgOpen.FileNames[0]);
}
cboFilename.SelectedValue = dlgOpen.FileNames[0];
Settings.Default.Save();