Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:56:30+00:00 2026-05-28T03:56:30+00:00

I’m implementing a basic search text box->button, but I also want to have the

  • 0

I’m implementing a basic search text box->button, but I also want to have the user be able to hit the Enter/Return key on the keyboard/pad, as per How to enable enter button on keyboard on wp7?

When the RelayCommand gets invoked, I just get a null value for the contents of the search text box.

I’m using MVVM Light.

I have a PhoneApplicationPage that is bound to a ViewModel with the properties:

public class MainViewModel : ViewModelBase

{

private string _searchString;

public RelayCommand Search { get; private set; }
public RelayCommand<KeyEventArgs> SearchTextBoxKeyDown { get; private set; }

public string SearchString
{
    get { return _searchString; }
    set
    {
        if (_searchString != value)
        {
            _searchString = value;
            RaisePropertyChanged("SearchString");
        }
    }
}

public MainViewModel()
{
    if (IsInDesignMode)
    {
        // Code runs in Blend --> create design time data.
    }
    else
    {
        // Code runs "for real"
        SearchTextBoxKeyDown=new RelayCommand<KeyEventArgs>((e)=>
        {
            if (e.Key == Key.Enter)
            {
                // SearchString is empty here?
                Search.Execute(null);
            }
        });
        Search = new RelayCommand(() =>
        { // invokes Search with SearchString

        },
        () =>
        {
            bool isEnabled = true;
            if (string.IsNullOrWhiteSpace(SearchString)) isEnabled = false;
            return isEnabled;
        });
    }
}

The View uses the MVVM Light toolkit to invoke the method for KeyDown on the AutoComplete control (it is a Telerik control, but it looks like a TextBox and smells like a TextBox):

                <telerikInput:RadAutoCompleteBox
                    InputScope="Search"
                    Text="{Binding SearchString,Mode=TwoWay}"
                    SuggestionsSource="{Binding MruSearchStrings}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="KeyDown">
                            <cmd:EventToCommand x:Name="searchStringTextBoxKeyDown" Command="{Binding SearchTextBoxKeyDown, Mode=OneWay}" PassEventArgsToCommand="True">
                            </cmd:EventToCommand>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </telerikInput:RadAutoCompleteBox>

In the invoked code, I just get null when I access the SearchString, which is what the TextBox is bound to – even though I have entered text into it. It’s almost as if the SearchTextBox has not sent its data back to the ViewModel for the ViewModel to pick up in the event code.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:56:30+00:00Added an answer on May 28, 2026 at 3:56 am

    Your ViewModel is not updated with value from TextBox because when you press Enter you still have focus in TextBox. By default, ViewModel will be updated after you leave TextBox control. However, you can change this situation by using custom behavior. This one works for me
    like a charm: http://zoltanarvai.com/2009/07/22/binding-update-on-textbox-textchanged-event-using-behaviors/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.