Wpf 可编辑组合框文本滚动
我有一个可编辑的wpf组合框。当我键入比长度长的内容而不是滚动到最后一个字符时,文本将失去控制且不可见。有没有办法解决这个问题Wpf 可编辑组合框文本滚动,wpf,Wpf,我有一个可编辑的wpf组合框。当我键入比长度长的内容而不是滚动到最后一个字符时,文本将失去控制且不可见。有没有办法解决这个问题 <ComboBox Margin="11,0,0,0" Height="23" Width="200" IsEditable="True" Text="{Binding Profile.Mat}"
<ComboBox Margin="11,0,0,0"
Height="23"
Width="200"
IsEditable="True"
Text="{Binding Profile.Mat}"
ItemsSource="{Binding Statuses}" />
您可以通过处理组合框模板中文本框的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;
}
}
如果这是你需要的,请告诉我。这个问题解决了吗?这对我不起作用。