开发者

WPF trigger template on every button

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜