2012-02-24 43 views
2

我有一个可编辑的wpf组合框。当我输入比其长度更长的东西而不是滚动到最后一个字符时,文本就会失控并且不可见。有没有什么办法解决这一问题?可编辑的组合框文本滚动

<ComboBox Margin="11,0,0,0" 
      Height="23"         
      Width="200" 
      IsEditable="True" 
      Text="{Binding Profile.Mat}" 
      ItemsSource="{Binding Statuses}" /> 

textscrolling

+0

这是否解决了?这不适合我。 – Ben 2016-04-29 03:20:09

回答

0

您可以通过处理组合框的模板中的文本框的SelectionChanged事件实现这一目标。在您的代码后面添加以下代码:

 public override void OnApplyTemplate() 
     { 
      base.OnApplyTemplate(); 
      if (comboBox.ApplyTemplate()) 
      { 
       TextBox editableTextBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox); 
       editableTextBox.SelectionChanged += new RoutedEventHandler(editableTextBox_SelectionChanged); 
      } 
     } 

     void editableTextBox_SelectionChanged(object sender, RoutedEventArgs e) 
     { 
      TextBox textBox = sender as TextBox; 
      if (textBox != null) 
      { 
       textBox.ScrollToHome(); 
       e.Handled = true; 
      } 
     } 
+0

让我知道这是你需要什么。 – gaurawerma 2012-02-24 13:20:00