我有一个可编辑的 wpf 组合框。当我输入比其长度长的内容而不是滚动到最后一个字符时,文本将脱离控制并且不可见。有没有什么办法解决这一问题?
<ComboBox Margin="11,0,0,0"
Height="23"
Width="200"
IsEditable="True"
Text="{Binding Profile.Mat}"
ItemsSource="{Binding Statuses}" />
您可以通过处理 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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)