bruce.du

now, I add a ComboBox to a Grid:IsEditable ="True" ;

the displaying text is from either keyboard input or selecteditem;

when the displaying text is changed, I want to get the displaying text.

now, the keyboard input event is "PreviewTextInput", and the selection-changed event is "SelectionChanged";

I must add two event function as follows:

void PreviewTextInput(Object sender, TextCompositionEventArgs e)
{

}
void SelectChanged(Object sender, SelectionChangedEventArgs e)
{

}

is there a shared-event to respose when the displaying text is changing

help me please!




Re: Windows Presentation Foundation (WPF) about the ComboBox's textChanged Event?

Yiling Lai

I know that ComboBox is made up by TextBox, Button and Popup, so it seems that we can add handler for TextBox.TextChanged event. But now I can't obtain the TextBox in ComboBox. ......






Re: Windows Presentation Foundation (WPF) about the ComboBox's textChanged Event?

Yiling Lai

Now, we can bind one TextBox to ComboBox and detect TextChanged event of TextBox like this:

<ComboBox Name="myComboBox" SelectedIndex="0">

<ComboBoxItem>1</ComboBoxItem>

<ComboBoxItem>2</ComboBoxItem>

<ComboBoxItem>3</ComboBoxItem>

</ComboBox>

<TextBox Text="{Binding ElementName=myComboBox, Path=Text}"

TextChanged="OnComboBoxTextChanged"/>

void OnComboBoxTextChanged(...)

{

}






Re: Windows Presentation Foundation (WPF) about the ComboBox's textChanged Event?

vapkse

Hello

You can access to the original textbox by this way, but only after the rendering

protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
{
base.OnRender(drawingContext);
TextBox txt = this.GetTemplateChild("PART_EditableTextBox") as TextBox;
txt.TextChanged += new TextChangedEventHandler(txt_TextChanged);
}

You need to add this code on your combobox C# part

and IsReadOnly="false" on the xaml part

Serge