WPF позволяет изменять значения между виртуальной машиной и представлением, используя IValueConverter
. Вы можете сделать что-то вроде этого:
public class GameListEmptyOptionValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var v = value as ObservableCollection<Game>;
v?.Insert(0, new Game() { Name = "NONE" });
return v;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
и, для его использования, на ваш взгляд:
<Window.Resources>
<local:GameListEmptyOptionValueConverter x:Key="GameListEmptyOptionValueConverter"/>
</Window.Resources>
<Grid>
<ComboBox ItemsSource="{Binding ., Converter={StaticResource GameListEmptyOptionValueConverter}}" DisplayMemberPath="Name"/>
</Grid>