This is a migrated thread and some comments may be shown as answers.
TextChanged Event
12 Answers 197 Views
This is a migrated thread and some comments may be shown as answers.
lkeel
Top achievements
Rank 1
lkeel asked on 16 Jun 2010, 02:21 AM
What is the WPF equivalent of the TextChanged event?  I have a RadComboBox that allows editing and when the text changes I need to raise perform some work.

Thanks in advance,
Lee

12 Answers, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 17 Jun 2010, 09:15 AM
Hello lkeel,

In WPF you can use TextBoxBase.TextChanged  event. So just set in xaml:
TextBoxBase.TextChanged="combo1_TextChanged"

Let me know if you need more help.

All the best,
Boyan
the Telerik team

If you want to reduce the size of your Silverlight application, you should check our latest Silverlight tool online - Assembly Minifier (http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx)

0
lkeel
Top achievements
Rank 1
answered on 17 Jun 2010, 05:49 PM
Apparently I am confused...  I don't see TextBoxBase as a property or method from the RadComboBox.  If my combobox is named "combo" then what code would I use to get to the TextBoxBase?  Is it a straight QI?
0
Boyan
Telerik team
answered on 22 Jun 2010, 11:33 AM
Hi lkeel,

TextBoxBase.TextChanged  is an attached property. Your XAML will look like this:
<telerikInput:RadComboBox Height="20" Width="200" x:Name="combo" TextBoxBase.TextChanged="combo_TextChanged" >
This way you will trigger this event with every symbol you type or every Text change. Then just put the code you want to execute in combo_TextChanged in the code behind.

Let me know if you have further questions.

Best wishes,
Boyan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ivano
Top achievements
Rank 1
answered on 27 Jan 2011, 03:12 PM
Hi

how can I do everything in code behind?

Thanks
0
Ken
Top achievements
Rank 1
answered on 30 May 2012, 05:11 PM
Something like this?

this.comboBox.AddHandler(TextBoxBase.TextChangedEvent, new RoutedEventHandler((o,e) =>
{
    var currentText = this.comboBox.Text;
  
    // do something now...
}));


0
Boyan
Telerik team
answered on 04 Jun 2012, 02:30 PM
Hello,

Yes this is will do, you can attach to the event in code this way.  If you are having problems making it work, we will be glad to help.

Kind regards,
Boyan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Anna Katrina
Top achievements
Rank 1
answered on 25 Aug 2015, 06:21 PM

Hi,

 I have trying to apply the same event on my radcombobox as well but seems like textchangedevent is no longer available

 

<telerik:RadComboBox x:Name="rcboDocSize" DisplayMemberPath="FontSizeName" IsEditable="True" MaxDropDownHeight="190" Width="70" SelectionChanged="rcboDocSize_SelectionChanged" StaysOpenOnEdit="True" />​

 

when i typedin it says, The property 'TextChanged' was not found in type 'RadComboBox'. Any help about this?

0
Nasko
Telerik team
answered on 26 Aug 2015, 11:45 AM
Hi Anna,

RadComboBox does not support TextChanged event by design. However, you have two appraoches that you could use in order to achieve the desired.

The first one is the proposed by Boyan below to use the TextBoxBase.TextChanged attached property:
<telerik:RadComboBox x:Name="rcboDocSize" DisplayMemberPath="FontSizeName" IsEditable="True" MaxDropDownHeight="190" Width="70" SelectionChanged="rcboDocSize_SelectionChanged" StaysOpenOnEdit="True"
TextBoxBase.TextChanged="radComboBox_TextChanged"/>​

and in code - behind:
private void radComboBox_TextChanged(object sender, TextChangedEventArgs e)
{
    //implement custom logic here
}

The second approach that you could use to handle to the TextChanged event is to get the TextBox placed inside RadComboBox using the ChildrenOfType method (inside the Loaded event) and handle its TextChanged event:
private void radComboBox_Loaded(object sender, RoutedEventArgs e)
{
    var combo = sender as RadComboBox;
    var textBox = combo.ChildrenOfType<TextBox>().FirstOrDefault();
    if(textBox != null)
    {
        textBox.TextChanged += textBox_TextChanged;
    }
}
 
void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
    //implement custom logic
}

Hopes this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Anna Katrina
Top achievements
Rank 1
answered on 26 Aug 2015, 05:16 PM

Thanks for the reply Nasko..

I have added the TextBoxBase.TextChanged="radComboBox_TextChanged" however it gives me this error on the xaml file:

 'The attachable property 'TextChanged' was not found in type 'TextBoxBase'

Am i missing header or something in the xaml?

 

I have also tried working with the loaded event but it throws me a framework element error..

 Thanks in advance. Your help is very much appreciated.

 

0
Nasko
Telerik team
answered on 28 Aug 2015, 10:52 AM
Hello Anna,

We tried to reproduce the observed by you error but it seems everything works as expected on our side.

I am attaching you a sample project that demonstrates the approach with the TextBoxBase.TextChanged attached event - please, check it.

Hopes this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Flemming
Top achievements
Rank 1
answered on 04 May 2018, 04:57 PM

How can I attach this event to a reactive linq event like this:

var input = (from evt in Observable.FromEventPattern(myradcombobox, "TextChanged")

var input = (from evt in Observable.FromEventPattern(myradcombobox, "TextBoxBase.TextChanged")

Both throws error that it's not found.

0
Martin Ivanov
Telerik team
answered on 09 May 2018, 10:37 AM
Hello Flemming,

I checked this on my side and I hit the following error  - "Could not find event 'TextChanged' on object of type 'Telerik.Windows.Controls.RadComboBox'.". I am not familiar with the Reactive Linq framework but I will guess that the FromEventPattern method is searching for direct events only. And since the TextChanged is not an event of RadComboBox you can't get the proper event pattern.

To achieve your requirement you can subscribe the Loaded event of the combobox where you can get the TextBox element and use the reactive linq on it.
private void Combobox_Loaded(object sender, RoutedEventArgs e)
{
    var textBox = this.combobox.FindChildByType<TextBox>();
    var input = from evt in Observable.FromEventPattern(textBox, "TextChanged") select evt;
}

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Asked by
lkeel
Top achievements
Rank 1
Answers by
Boyan
Telerik team
lkeel
Top achievements
Rank 1
Ivano
Top achievements
Rank 1
Ken
Top achievements
Rank 1
Anna Katrina
Top achievements
Rank 1
Nasko
Telerik team
Flemming
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or