Search code examples
wpfstylessetterinteraction

WPF Style setter Inputbindings


This code is not issue. But i want partial InterAction and InputBindings.

<Window>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <i:InvokeCommandAction Command="{Binding ExamCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Window.InputBindings>
        <KeyBinding Key="Esc" Command="{Binding WindowKeyDownESCCommand}"/>
    </Window.InputBindings>
    <Grid>
        <!-- Some Xaml Elements ... -->
    </Grid>
</Window>

But I want do create Window style.

Like this.

<Window Style="{StaticResource MyWindowStyle}" />

<Style x:Key="MyWindowStyle" TargetType="Window">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <i:InvokeCommandAction Command="{Binding ExamCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Window.InputBindings>
        <KeyBinding Key="Esc" Command="{Binding WindowKeyDownESCCommand}"/>
    </Window.InputBindings>
</Style>

Solution

  • Thanks for my question and I think I probably solved it.

    Here.

    <Style TargetType="Window">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Window">
                    <ContentPresenter>
                        <ContentPresenter.Triggers>
                           <!-- Here i:InteractionTrigger -->
                        </ContentPresenter.Triggers>
                        <ContentPresenter.InputBindings>
                           <!-- Here InputBindings -->
                        </ContentPresenter.InputBindings>
                    </ContentPresenter>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    And thank you for your interest in spite of the lack of explanation.

    Have a good day!!