What is the best approach to pass the current view model state - specifically what textbox has focus - back to the view model?
My requirement is for context specific search, depending what text box has focus determines what field to search on in the database.
I'm using the MVVM pattern and really don't want to put any code in the view.
create an attached property for the TextBox which is an IsFocussed property. Then use 2 way binding to your ViewModel
You could use the InvokeCommandAction available in the Expression Blend SDK:
<StackPanel>
<TextBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="GotFocus">
<i:InvokeCommandAction Command="{Binding YourCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</StackPanel>
Where:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With