I'm working on a WPF project using the MVVM pattern. I need to add a trigger to send a routed command to the view model for every textbox on all of my edit screens.
I would like to do this by using a style in by resource dictionary that I apply to all of my textboxes. To make life easy, I would like to do the command binding in the resource dictionary. Something like the following -
<Style x:Key="EditText开发者_运维知识库Box" TargetType="{x:Type TextBox}">
<Style.Triggers>
<EventTrigger RoutedEvent="Control.IsFocused">
<Actions:InvokeCommand Command="{Binding UpdateHelpCommand}" CommandParameter="{Binding}"/>
</EventTrigger>
</Style.Triggers>
</Style>
Where Actions:InvokeCommand is a From the JulMar MVVM Helpers + Behaviors library. This function calls a routed command in view model.
Any suggestions as to how this can be done without manually adding it to each control?
What is stopping you from using a typed Style (Style without a key defined) instead of the named Style that you are currently using? That would do away with the need to specify the Style for each textbox.
精彩评论