Adding a commandparameter to KeyBinding

4 posts, 0 answers
  1. Jason Mesches
    Jason Mesches avatar
    5 posts
    Member since:
    Dec 2009

    Posted 17 Dec 2009 Link to this post

    Hi,

    Using a VM pattern and trying to bind my the <ENTER> key to a command that is on my ViewModel.  This seems to work as long as I make the property static and access the static constructor as outlined.  The issue comes with trying to bind a command parameter to the value of a RadMaskedTextbox.  This is to implement search capability... the textbox has the search criteria and the <ENTER> key triggers the search.  The command seems to fire just fine, no matter what I try I can't seem to get the command parameter to be wired to my textbox. 

    And yes, btw, the textbox does have an x:Name

    Thanks,
    ---Jason


  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 23 Dec 2009 Link to this post

    Hi Jason Mesches,

    Wich command patter implementation you are using? Do you have the same problem with a normal textbox, or just with the MaskedTextBox?


    Regards,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jason Mesches
    Jason Mesches avatar
    5 posts
    Member since:
    Dec 2009

    Posted 29 Dec 2009 Link to this post

    Hi, Valentin

    Thanks for the reply.  Here's what I found.  First issue is with the RadMaskedTextBox... we had the Mask set to "none" and apparently there are still issues with that setting.  Once I corrected that, I was up against the fact that key bindings don't support CommandParameter as a dependency property which makes binding difficult.

    We're trying to remove all code from our views and only bind to our view models... maybe you can point me to a decent implementation of a search pattern (e.g. search customer by phone number) with telerik controls that binds to a view model without code-behind?

    I found a few examples of something similar online, but they all seem to involve heavy use of static methods and constructors and that smells of "hack" to me.  I think we may end up setting up the bindings in code (in the view model) anyway for our project.  The issue I'm facing now is that I have to reference the control when using SetInputBindings as the first parameter is a reference to the control the bindings are attached to (CommandManager.SetInputBindings(myView.myTextBox, inputBindingCollection)) -- and that part about specifically referring to the control is troublesome to me.  Any ideas on how to get around my ViewModel knowing that much about the View?

    Thanks,
    ---Jason
  4. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 05 Jan 2010 Link to this post

    Hello Jason,

    Actually you should code behind at least for the command and key bindings. About using the value of the RadMaskedTextBox - you can bind it to a property of your view model. Please preview the attached example and let us know if you have other questions.

    Regards,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top