TextChanged Event

13 posts, 0 answers
  1. lkeel
    lkeel avatar
    115 posts
    Member since:
    Jul 2012

    Posted 15 Jun 2010 Link to this post

    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
  2. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 17 Jun 2010 Link to this post

    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)

  3. lkeel
    lkeel avatar
    115 posts
    Member since:
    Jul 2012

    Posted 17 Jun 2010 Link to this post

    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?
  4. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 22 Jun 2010 Link to this post

    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
  5. Ivano
    Ivano avatar
    39 posts
    Member since:
    Feb 2009

    Posted 27 Jan 2011 Link to this post

    Hi

    how can I do everything in code behind?

    Thanks
  6. Ken
    Ken avatar
    3 posts
    Member since:
    Dec 2011

    Posted 30 May 2012 Link to this post

    Something like this?

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


  7. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 04 Jun 2012 Link to this post

    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 >>

  8. Anna Katrina
    Anna Katrina avatar
    9 posts
    Member since:
    Feb 2013

    Posted 25 Aug 2015 Link to this post

    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?

  9. Nasko
    Admin
    Nasko avatar
    727 posts

    Posted 26 Aug 2015 Link to this post

    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
  10. Anna Katrina
    Anna Katrina avatar
    9 posts
    Member since:
    Feb 2013

    Posted 26 Aug 2015 in reply to Nasko Link to this post

    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.

     

  11. Nasko
    Admin
    Nasko avatar
    727 posts

    Posted 28 Aug 2015 Link to this post

    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
  12. Flemming
    Flemming avatar
    14 posts
    Member since:
    Aug 2015

    Posted 04 May 2018 Link to this post

    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.

  13. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2240 posts

    Posted 09 May 2018 Link to this post

    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.
Back to Top