Syncfusion GridTemplateColumn第一个键入的字母被忽略

时间:2018-09-17 23:56:26

标签: c# caliburn.micro syncfusion

enter image description here我在页面上生成了GridTemplateColumn和GridTextColumn网格, 当我进入编辑模式时,带有GridTextColumn的列不会忽略第一个字母,而GridTemplateColumn会忽略第一个字母。 例如,如果我单击该列并开始输入f d s a,我只会看到d s,而忽略了“ f”。 在GridTextColumn中,如果键入f d a,我会看到所有字母。 f d s a。

我将所有GridTemplateColumn更改为GridTextColumn。 但有人告诉我不要这样做,我们需要GridTemplateColumn并找到另一个解决方案。

某些代码:

var column = new GridTemplateColumn
        {
            MappingName=$"e.Column.MappingName}.
                      nameof(ScribeDevicePropertyViewModel.BindingObject)}",
            HeaderText = headerText,
            SetCellBoundValue = true,
            UseBindingValue = true,
            ImmediateUpdateColumnFilter = true,
            ColumnFilter = ColumnFilter.DisplayText,
            GroupMode = DataReflectionMode.Display,
            FilterRowCondition = FilterRowCondition.Contains,
            CellStyle = grid.TryFindResource("DevicePropertyCellStyle") as 
    Style,
            CellTemplate = 
    grid.TryFindResource("DevicePropertyCellTemplate") as DataTemplate,
            EditTemplateSelector = new 
    ScribeDevicePropertyCellEditTemplateSelector()

    // and in xaml file also:

    <syncfusion:GridTemplateColumn
                        Width="200"
                        CellStyle="{StaticResource DevicePropertyCellStyle}"
                        CellTemplate="{StaticResource 
    DevicePropertyCellTemplate}"
                        EditTemplateSelector="{StaticResource 
                        ScribeDevicePropertyCellEditTemplateSelector}"
                        MappingName="Value" />
        };

1 个答案:

答案 0 :(得分:0)

您可以通过为GridTemplateColumn编写CustomRenderer并重写SetFocus方法来实现要求,如下面的代码片段

this.AssociatedObject.CellRenderers.Remove("Template");  
this.AssociatedObject.CellRenderers.Add("Template", new CustomGridCellTemplateRenderer());  

public class CustomGridCellTemplateRenderer : GridCellTemplateRenderer  
{  
     protected override void SetFocus(FrameworkElement uiElement, bool needToFocus)  
     {  
          base.SetFocus(uiElement, needToFocus);  
          var focusedElement = FocusManagerHelper.GetFocusedUIElement(CurrentCellRendererElement);  
          TextBox textBox = focusedElement as TextBox;  
          if(textBox == null)  
          {  
              var comboBox = focusedElement as ComboBox;  
              if(comboBox != null && comboBox.IsEditable)  
              {  
                  textBox = (TextBox)GridUtil.FindDescendantChildByType(comboBox, typeof(TextBox));  
              }  
          }  
          if (textBox != null)  
          {  
              if (PreviewInputText == null)  
              {  
                  var index = textBox.Text.Length;  
                  textBox.Select(index + 1, 0);  
                  return;  
              }  
              textBox.Text = PreviewInputText;  
              var caretIndex = (textBox.Text).IndexOf(PreviewInputText.ToString());  
              textBox.Select(caretIndex + 1, 0);  
              PreviewInputText = null;  
          }  
     }  
}  

请从下面的链接中找到相同的示例,请告诉我们这是否对您有帮助
http://www.syncfusion.com/downloads/support/directtrac/215268/ze/WPF-678839977

注意:我正在为Syncfusion工作