photo_tom
photo_tom

Reputation: 7342

Binding to Routed Command in Resource Dictionary

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="EditTextBox" 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?

Upvotes: 0

Views: 1414

Answers (1)

Black Jack Pershing
Black Jack Pershing

Reputation: 126

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.

Upvotes: 1

Related Questions