コード例 #1
0
        private UIElement BindCheckBoxElement(TuningPropertyWrapViewModel tuningPropertyWrapViewModel, string bindingPath)
        {
            Binding binding = new Binding(bindingPath)
            {
                Mode = BindingMode.TwoWay,
                Source = tuningPropertyWrapViewModel,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };

            CmsCheckBox checkBox = new CmsCheckBox();
            checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
            checkBox.VerticalAlignment = VerticalAlignment.Center;
            checkBox.Margin = new Thickness(1);

            checkBox.ResetOriginalValue();
            checkBox.ControlChanged += ControlChanged;

            UIElement returnElement = checkBox;
            checkBox.IsEnabled = tuningPropertyWrapViewModel.TuningProperty.IsEditable;

            return returnElement;
        }
コード例 #2
0
        private FrameworkElement BindElementValue(ControlTestingPropertyWrapViewModel wrapViewModel, IEnumerable<PropertyList> propertyLists, List<string> pidDocuments, List<string> specDocuments)
        {
            UIElement returnElement = new CmsCheckBox();

            var binding = new Binding("Value")
            {
                Mode = BindingMode.TwoWay,
                Source = wrapViewModel,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };
            Grid grid;

            switch (wrapViewModel.PropertyType)
            {
                case CommonUtils.PropertyType.Numerical:
                case CommonUtils.PropertyType.Text:
                case CommonUtils.PropertyType.LargeText:
                    var newCmsTextBox = new CmsTextBox();
                    newCmsTextBox.SetBinding(TextBox.TextProperty, binding);
                    newCmsTextBox.VerticalAlignment = VerticalAlignment.Center;
                    newCmsTextBox.Margin = new Thickness(1);

                    newCmsTextBox.ResetOriginalValue();
                    newCmsTextBox.ControlChanged += ControlChanged;

                    if (wrapViewModel.PropertyType == CommonUtils.PropertyType.LargeText) newCmsTextBox.AcceptsReturn = true;

                    returnElement = newCmsTextBox;
                    newCmsTextBox.IsReadOnly = !wrapViewModel.ControlTestingProperty.IsEditable;
                    break;

                //SystemComboBox
                case CommonUtils.PropertyType.SystemComboBox:
                    var cmsSystemComboBox = new CmsComboBox { Margin = new Thickness(1) };

                    var items = new List<string>();

                    if (wrapViewModel.ControlTestingProperty.SystemComboType == CommonUtils.SystemComboBoxType.PandIdDocuments.ToString())
                    {
                        items = pidDocuments;
                    }
                    else if (wrapViewModel.ControlTestingProperty.SystemComboType == CommonUtils.SystemComboBoxType.SpecificationDocuments.ToString())
                    {
                        items = specDocuments;
                    }

                    if (items != null)
                    {
                        wrapViewModel.ListValues = items;

                        var valuesBinding = new Binding("ListValues")
                        {
                            Mode = BindingMode.OneTime,
                            Source = wrapViewModel
                        };

                        cmsSystemComboBox.ItemTemplate = GetPropertyComboDataTemplate();
                        cmsSystemComboBox.SetBinding(ItemsControl.ItemsSourceProperty, valuesBinding);
                        cmsSystemComboBox.SetBinding(Selector.SelectedValueProperty, binding);

                        cmsSystemComboBox.VerticalAlignment = VerticalAlignment.Center;
                        cmsSystemComboBox.Height = 24;

                        cmsSystemComboBox.ResetOriginalValue();
                        cmsSystemComboBox.ControlChanged += ControlChanged;
                    }
                    cmsSystemComboBox.IsEnabled = wrapViewModel.ControlTestingProperty.IsEditable;
                    if (!wrapViewModel.ControlTestingProperty.IsEditable)
                    {
                        cmsSystemComboBox.Foreground = new SolidColorBrush(Color.FromArgb(255, 61, 61, 91));
                    }
                    returnElement = cmsSystemComboBox;
                    break;

                //ComboBox
                case CommonUtils.PropertyType.ComboBox:

                    var cmsComboBox = new CmsComboBox
                    {
                        Margin = new Thickness(1)
                    };

                    var propertyListNames = (from x in propertyLists
                                             where x.Id == wrapViewModel.ControlTestingProperty.PropertyListId
                                             select x.PropertyListNames).FirstOrDefault();

                    if (propertyListNames != null)
                    {
                        //Client asked for a Description to be included in the brackets
                        //In ideal world this should be binded to list of PropertyList objects
                        //and have display item set to a FormattedName
                        //
                        //Current solution is not the great for sure, but best in the current situation
                        //(can't afford to rewrite this)
                        var listNames = (from x in propertyListNames
                                         orderby x.Ordinal
                                         select !string.IsNullOrEmpty(x.Description)
                                             ? x.Name + "  (" + x.Description + ")" :
                                             x.Name).ToList();

                        wrapViewModel.ListValues = listNames;

                        var valuesBinding = new Binding("ListValues")
                        {
                            Mode = BindingMode.OneTime,
                            Source = wrapViewModel
                        };

                        cmsComboBox.ItemTemplate = GetPropertyComboDataTemplate();
                        cmsComboBox.SetBinding(ItemsControl.ItemsSourceProperty, valuesBinding);
                        cmsComboBox.SetBinding(Selector.SelectedValueProperty, binding);

                        cmsComboBox.VerticalAlignment = VerticalAlignment.Center;
                        cmsComboBox.Height = 24;

                        cmsComboBox.ResetOriginalValue();
                        cmsComboBox.ControlChanged += ControlChanged;
                    }
                    cmsComboBox.IsEnabled = wrapViewModel.ControlTestingProperty.IsEditable;
                    if (!wrapViewModel.ControlTestingProperty.IsEditable)
                    {
                        cmsComboBox.Foreground = new SolidColorBrush(Color.FromArgb(255, 61, 61, 91));
                    }
                    returnElement = cmsComboBox;
                    break;

                //CheckBox
                case CommonUtils.PropertyType.CheckBox:
                    var cmsCheckBox = new CmsCheckBox();

                    binding.Converter = new StringToBooleanConverter();
                    cmsCheckBox.SetBinding(ToggleButton.IsCheckedProperty, binding);
                    cmsCheckBox.VerticalAlignment = VerticalAlignment.Center;

                    cmsCheckBox.ResetOriginalValue();
                    cmsCheckBox.ControlChanged += ControlChanged;

                    grid = new Grid();
                    grid.Children.Add(cmsCheckBox);

                    cmsCheckBox.IsEnabled = wrapViewModel.ControlTestingProperty.IsEditable;
                    returnElement = grid;
                    break;

                //VerifiedCheckBox
                case CommonUtils.PropertyType.VerifiedCheckBox:

                    grid = new Grid();
                    grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20) });
                    grid.ColumnDefinitions.Add(new ColumnDefinition());

                    var checkBox = new CmsCheckBox();

                    binding.Converter = new StringToBooleanConverter();
                    checkBox.SetBinding(ToggleButton.IsCheckedProperty, binding);
                    checkBox.VerticalAlignment = VerticalAlignment.Center;

                    checkBox.ResetOriginalValue();
                    checkBox.ControlChanged += ControlChanged;
                    checkBox.IsEnabled = wrapViewModel.ControlTestingProperty.IsEditable;

                    var verifiedUserDateBinding = new Binding("VerifiedUserDate")
                    {
                        Mode = BindingMode.OneWay,
                        Source = wrapViewModel
                    };

                    var textBox = new TextBox { IsReadOnly = true, VerticalAlignment = VerticalAlignment.Center };
                    textBox.SetBinding(TextBox.TextProperty, verifiedUserDateBinding);

                    grid.Children.Add(checkBox);
                    grid.Children.Add(textBox);

                    Grid.SetRow(checkBox, 0);
                    Grid.SetRow(textBox, 0);
                    Grid.SetColumn(checkBox, 0);
                    Grid.SetColumn(textBox, 1);

                    returnElement = grid;
                    break;
            }

            ((FrameworkElement)returnElement).Height = wrapViewModel.PropertyType == CommonUtils.PropertyType.LargeText ? 98 : 23;
            return (FrameworkElement)returnElement;
        }