我有一个 ComboBox,我想将边框的颜色更改为红色以将其标记为必填字段。我正在通过我的代码动态生成这个 ComboBox 列。为了更改边框颜色,我应该设置哪些属性?
DataGridTemplateColumn dataGridComboBoxTemplateColumnObj = new DataGridTemplateColumn();
dataGridComboBoxTemplateColumnObj.Header = column.Header;
FrameworkElementFactory comboBoxFactory = new FrameworkElementFactory(typeof(ComboBox));
Binding bindingItemSourceObj = new Binding(column.ItemsSourcePropertyName);
comboBoxFactory.SetValue(ComboBox.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
comboBoxFactory.SetValue(ComboBox.ItemsSourceProperty, bindingItemSourceObj);
comboBoxFactory.SetValue(ComboBox.SelectedValuePathProperty, column.ValuePropertyName);
Binding selectedValueBindingObj = new Binding(column.PropertyName);
selectedValueBindingObj.Mode = BindingMode.TwoWay;
selectedValueBindingObj.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
comboBoxFactory.SetValue(ComboBox.SelectedValueProperty, selectedValueBindingObj);
dataGridComboBoxTemplateColumnObj.CellTemplate = new DataTemplate();
dataGridComboBoxTemplateColumnObj.CellTemplate.VisualTree = comboBoxFactory;
dataGridColumnObj = dataGridComboBoxTemplateColumnObj;