开发者

WPF trigger template on every button

开发者 https://www.devze.com 2023-04-04 09:45 出处:网络
I have created a Button with the following trigger: <Button Content=\"Test> <i:Interaction.Triggers>

I have created a Button with the following trigger:

                    <Button Content="Test>
                      <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <cal:ActionMessage MethodName="SetViewModelToOpen">
                                <cal:Parameter Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadButton}},Path=Content}" />
                            </cal:ActionMessage>
                        </i:EventTrigger>
                      &l开发者_JS百科t;/i:Interaction.Triggers>
                    </Button>

Now I have several button like this one and want this trigger to be applied to every button. How to do this?


You need to use styles, in your case:

<Style x:Key="ButtonWithTriggers" TargetType="Button">
    <Style.Triggers>
        <Trigger Property="IsPressed" Value="true">
            <[Place your actions here]>
        </Trigger>
     </Style.Triggers>
</Style>

Then your button declaration:

<Button Content="Test" Style="{StaticResource ButtonWithTriggers}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消