我有一个可编辑的wpf组合框。当我输入长度超过其长度的内容而不是滚动到最后一个字符时,文本会退出控件并且不可见。有没有什么办法解决这一问题?
<ComboBox Margin="11,0,0,0"
Height="23"
Width="200"
IsEditable="True"
Text="{Binding Profile.Mat}"
ItemsSource="{Binding Statuses}" />
答案 0 :(得分:0)
您可以通过处理ComboBox模板中TextBox的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;
}
}