Button.Template WPF [英] Button.Template WPF

查看:23
本文介绍了Button.Template WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了包含网格的大按钮,如下所示:

I`ve created big button which contains grid as below:

   <Button Height="Auto" Width="Auto" Command="{Binding ContinueWithoutScan}" BorderThickness="0">
                <Button.Template>
                    <ControlTemplate>
                        <Grid >
                            <TextBlock  HorizontalAlignment="Center"
                                       TextWrapping="Wrap" Text="Text"
                                       VerticalAlignment="Center" FontWeight="DemiBold" 
                                       Height="Auto" Width="Auto"
                                       FontSize="25" Foreground="White"/>
                            <materialDesign:PackIcon Height="Auto" Width="70"  Kind="ChevronRight" Foreground="White"
                                     VerticalAlignment="Center"  HorizontalAlignment="Right"/>
                        </Grid>
                    </ControlTemplate>
                </Button.Template>
            </Button>

存在只有 Template 内的 TextBlock 可点击的问题.有谁知道如何使整个内容可点击?我使用 MVVM,所以我不想制作 Grid.OnMouseEneter.

There is problem that only TextBlock inside Template is clickable. Does anyone know how do I make whole content clickable? I working with MVVM so I dont want make Grid.OnMouseEneter.

是否可以选择使用 EventTriggers?

Is there option to do that of I have to use EventTriggers?

推荐答案

网格需要有一个不同于默认 null 的背景来接收输入事件.您可以设置透明背景而不是 null:

The Grid needs to have a Background other than the default null to receive input events. You may set a transparent background instead of null:

<Grid Background="Transparent">
    ...
</Grid>

这篇关于Button.Template WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆