Provides a simple logical representation of a ComboBox.
For simple binding, set this as the DataContext of a CoreComboBox.
Inheritance: ViewModelBase
        private static ComboBoxViewModel CreateComboBox(ViewTestParameter parameter)
        {
            // Setup initial conditions.
            var viewModel = new ComboBoxViewModel
                                {
                                    ToolTip = string.Format("Parameter: {0}", parameter.Info.Name)
                                };

            // Populate with values.
            if (parameter.Type.IsEnum)
            {
                PopulateEnumDropdown(viewModel, parameter);
            }
            else if (parameter.Type.IsA(typeof(bool)))
            {
                PopulateBooleanDropdown(viewModel, parameter);
            }

            // Wire up events.
            Action syncParameterValue = () => { parameter.Value = viewModel.SelectedItemValue; };
            viewModel.SelectionChanged += delegate { syncParameterValue(); };

            // Finish up.
            syncParameterValue();
            return viewModel;
        }
 private static void PopulateEnumDropdown(ComboBoxViewModel viewModel, ViewTestParameter parameter)
 {
     foreach (var value in parameter.Type.GetEnumValues())
     {
         viewModel.Add(value.ToString(), value);
     }
     SelectDefaultValue(viewModel, parameter.Info.DefaultValue);
 }
        private static void PopulateBooleanDropdown(ComboBoxViewModel viewModel, ViewTestParameter parameter)
        {
            var name = parameter.Info.Name;
            viewModel.Add(string.Format("{0}: True", name), true);
            viewModel.Add(string.Format("{0}: False", name), false);

            var defaultValue = parameter.Info.DefaultValue;
            SelectDefaultValue(
                            viewModel,
                            defaultValue is DBNull ? false : defaultValue);
        }
 private static void SelectDefaultValue(ComboBoxViewModel viewModel, object defaultValue)
 {
     var hasDefault = viewModel.Items.Count(m => Equals(m.Value, defaultValue)) > 0;
     if (hasDefault)
     {
         viewModel.SelectValue(defaultValue);
     }
     else
     {
         viewModel.SelectFirst();
     }
 }
        public void Initialize(CoreComboBox control)
        {
            // Setup initial conditions.
            control.Width = 300;
            control.Padding = new Thickness(20, 5, 20, 5);

            // Setup view-model.
            viewModel = new ComboBoxViewModel();
            control.ViewModel = viewModel;

            // Wire up events.
            viewModel.SelectionChanged += delegate { Debug.WriteLine("!! SelectionChanged: " + viewModel.SelectedItem); };

            // Finish up.
            Build_Items_Collection(control);
        }