【问题标题】:Icon inside material design button doesn't click材料设计按钮内的图标没有点击
【发布时间】:2020-08-31 13:49:09
【问题描述】:

我正在使用 C# WPF 和 Material Design。

我有这个按钮

        <Button x:Name="btnClose"
                Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
                Style="{StaticResource MaterialDesignIconForegroundButton}"
                Background="White"
                BorderBrush="Transparent"
                Cursor="Hand"
                VerticalAlignment="Top"
                HorizontalAlignment="Right"
                Margin="0 20 25 0">
            <materialDesign:PackIcon Kind="Close"
                                     Foreground="Gray"
                                     Height="28"
                                     Width="28" />
            <Button.CommandParameter>
                <system:Boolean>False</system:Boolean>
            </Button.CommandParameter>
        </Button>

但我看到,当光标在按钮内的图标上时,光标不会变成手形,点击也不起作用。

有人知道为什么会这样吗?

【问题讨论】:

  • 您是否检查了您的命令的CanExecute 是否返回true?。尝试删除命令绑定并查看它是否重新启用。可以发一下CloseDialogCommand的内容吗?
  • 问题在于您选择的按钮样式。他们用于 close packicon 的图标或路径将 X 创建为缺席。它不是图标,因此也不是前景。您选择了 MaterialDesignIconForegroundButton,似乎固有的设计是使前景(您选择的图标)成为唯一可点击的部分。
  • 我认为 Material Design 样式中存在一个错误,因为我看到当我不在按钮中放置边距时,问题不会发生,只有当我定义边距时才会发生问题。感谢您的帮助。

标签: c# wpf button material-design


【解决方案1】:

Here我能找到这个。

/// Routed command to be used inside dialog content to close a dialog. Use a <see cref="Button.CommandParameter"/> to indicate the result of the parameter.
/// </summary>
public static RoutedCommand CloseDialogCommand = new RoutedCommand();

这意味着你应该改变

<Button.CommandParameter>
    <system:Boolean>False</system:Boolean>
</Button.CommandParameter>

<Button.CommandParameter>
    <system:Boolean>True</system:Boolean>
</Button.CommandParameter>

【讨论】:

    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多