Quantcast
Viewing all articles
Browse latest Browse all 5

Enter Button Behavior

It fires a number of events that normally don't fire in MVVM. Here's how I hook up the textbox

<TextBox Text="{Binding NewText, Mode=TwoWay}"><i:Interaction.Behaviors><behaviors:TextBoxUpdateBehavior/></i:Interaction.Behaviors><i:Interaction.Triggers><i:EventTrigger EventName="KeyUp"><cmd:EventToCommand Command="{Binding KeyUpCommand}" PassEventArgsToCommand="True"/></i:EventTrigger></i:Interaction.Triggers></TextBox>

Then in the Codebehind (I use MVVMLight for Commands)

    Public ReadOnly Property KeyUpCommand As RelayCommand(Of KeyEventArgs)
        Get
            Return New RelayCommand(Of KeyEventArgs)(Sub(e)

                                                         If e.Key = Key.Enter Then
                                                             ' call the code that button would normally
                                                         End If

                                                     End Sub)
        End Get
    End Property

Graeme


Viewing all articles
Browse latest Browse all 5

Trending Articles