以路径为内容的WPF按钮

时间:2018-07-09 17:59:09

标签: c# .net wpf xaml

我遇到了一件有趣的事情,目前我不知道该如何解决,也许我错过了一个非常简单的东西。

我正在重新设计一些UI,但是现在我还没有真正的经验。 所以我有3个按钮,我想绘制图案作为按钮的内容,而不是使用图像。

我设法做到了(仍然需要调整),但是只有当我的指针进入模式区域而不是按钮区域时,悬停事件上的按钮才会触发。有人介意看看吗?

import random
numbers = random.sample(range(10), 4)

代码:https://codeburst.io/api-authentication-in-laravel-vue-spa-using-jwt-auth-d8251b3632e0

1 个答案:

答案 0 :(得分:0)

通过将按钮的背景和边框笔刷设置为空,按钮将仅在绘制路径的悬停时可单击和检测到。将null替换为Transparent或#00000000,按钮将不可见,但可以单击/悬停(如果是这样的话)

<Button Grid.Column="0" Width="35" Height="35" 
        Command="{StaticResource MinimizeCommand}"
        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" 
        Background="Transparent" BorderBrush="#00000000">
    <Path Data="M20,14H4V10H20" VerticalAlignment="Center" HorizontalAlignment="Center" Height="2.6" Margin="7,20,7,10" Stretch="Fill" Width="16">
         <Path.Fill>
             <SolidColorBrush Color="{DynamicResource MainForeColor}"/>
         </Path.Fill>
    </Path>
</Button>