WPF C1FlexGrid中重写编辑模板绑定下拉与验证效果冲突问题
本帖最后由 CanYou8 于 2016-5-14 11:27 编辑在WPF C1FlexGrid的CellFactory中重写了CreateCellContentEditor方法,以便给需要的单元格绑定下拉框
/// <summary>
/// 重写 单元格编辑模板
/// </summary>
public override void CreateCellContentEditor(C1FlexGrid grid, Border bdr, CellRange range)
{
base.CreateCellContentEditor(grid, bdr, range);
// get row/col
var row = grid.Rows;
var col = grid.Columns;
if (null == row.DataItem) return;
var model = row.DataItem as ParamModel;
if (null == model) return;
// 参数值列的控制
if (_isReadOnly || col.ColumnName != "ParamValue") return;
//绑定部分参数值列为下拉框
if (!string.IsNullOrEmpty(model.MembersCollection))
{
var arr = model.MembersCollection.Split(',');
if (arr.Any())
{
_paramValueList.Clear();
foreach (string i in arr)
{
_paramValueList.Add(new { value = i, name = i });
}
}
C1ComboBox comboBox = new C1ComboBox();
comboBox.VerticalAlignment = VerticalAlignment.Center;
comboBox.HorizontalAlignment = HorizontalAlignment.Center;
comboBox.SetResourceReference(C1ComboBox.StyleProperty, "Grid-AutoComboBox-List");
comboBox.Margin = _emptyThickness;
comboBox.Watermark = string.Empty;
comboBox.Width = 120;
comboBox.DisplayMemberPath = "name";
comboBox.SelectedValuePath = "value";
comboBox.ItemsSource = _paramValueList;
Binding binding = new Binding();
binding.Path = new PropertyPath("ParamValue");
binding.Mode = BindingMode.TwoWay;
comboBox.SetBinding(C1ComboBox.TextProperty, binding);
comboBox.IsDropDownOpen = true;
bdr.Margin = _emptyThickness;
bdr.Padding = _emptyThickness;
bdr.Child = comboBox;
}
}在xaml文件中定义C1FlexGrid
<c1:C1FlexGrid Name="c1FlexGrid"ItemsSource="{Binding List,IsAsync=True}"
PreviewKeyDown="c1FlexGrid_PreviewKeyDown"
LoadedRows="c1FlexGrid_LoadedRows"
SelectionChanged="c1FlexGrid_SelectionChanged">
<c1:C1FlexGrid.Columns>
<c1:Column Header="参数值" Width="5*" Binding="{Binding ParamValue, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
</c1:C1FlexGrid.Columns>
</c1:C1FlexGrid>但是当提示参数值必填时,下拉选择的效果就没有了,请问如何解决这个问题?
在以下demo测试,但无法重现你的问题。
测试的demo如下,供您参考:
\Documents\ComponentOne Samples\WPF\C1.WPF.FlexGrid\CS\MultiColumnCombo\MultiColumnCombo
\Documents\ComponentOne Samples\WPF\C1.WPF.FlexGrid\CS\Validation\Validation
页:
[1]