Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF CustomControl-按钮赢得';t火点击事件_C#_Wpf_Xaml_Command_Custom Controls - Fatal编程技术网

C# WPF CustomControl-按钮赢得';t火点击事件

C# WPF CustomControl-按钮赢得';t火点击事件,c#,wpf,xaml,command,custom-controls,C#,Wpf,Xaml,Command,Custom Controls,我创建了一个方形按钮,作为带有绑定和其他东西的CustomControl,以“重新获得一些编程技能”(学习目的) 现在我遇到了一个问题,我的自定义命令不会被触发。在我检查了所有我能找到的东西之后,我直接测试了点击事件,但是即使点击事件本身也不会被触发 自定义控件: <UserControl x:Class="SGDB.Controls.QuadButton" x:Name="QButton" xmlns="http://schemas.microsoft

我创建了一个方形按钮,作为带有绑定和其他东西的CustomControl,以“重新获得一些编程技能”(学习目的)

现在我遇到了一个问题,我的自定义命令不会被触发。在我检查了所有我能找到的东西之后,我直接测试了点击事件,但是即使点击事件本身也不会被触发

自定义控件:

<UserControl x:Class="SGDB.Controls.QuadButton"
         x:Name="QButton"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:SGDB.Controls"
         mc:Ignorable="d"
         d:DesignHeight="100" d:DesignWidth="100" Margin="2,2,2,2">
<UserControl.Resources>
    <Style TargetType="Button">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="#003264" Offset="0.25"/>
                    <GradientStop Color="#004896" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="TextBlock">
        <Setter Property="Foreground">
            <Setter.Value>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="#FFCD9B" Offset="0.25"/>
                    <GradientStop Color="#FFB769" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="FontWeight" Value="Black"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=IsMouseOver}"  Value="True">
                <Setter Property="Foreground">
                    <Setter.Value>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                            <GradientStop Color="#411902" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>
<Border BorderThickness="1" BorderBrush="White">
    <Button Width="{Binding Size, ElementName=QButton}" Height="{Binding Size, ElementName=QButton}" Command="{Binding ExecuteCommand, ElementName=QButton}" Click="Button_Click">
        <StackPanel Margin="10">
            <Image Source="{Binding ImageSource, ElementName=QButton}" Width="64" Height="64" HorizontalAlignment="Center" VerticalAlignment="Top"/>
            <TextBlock Text="{Binding DisplayText, ElementName=QButton}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0"/>
        </StackPanel>
    </Button>
</Border>
使用自定义按钮的视图中的命令:

<custom:QuadButton Size="200" DisplayText="Administration" ImageSource="../Pictures/Users.png" ExecuteCommand="{Binding VM.TestButton}"/>


(VM=ViewModel,TestButton=用于测试按钮的命令)

这是我的错-我实现了一些代码以使我的窗口可拖动-现在我知道这种方法正在吞噬MouseDown事件。

当您尝试使用命令和同一按钮上的单击事件时,会发生一些奇怪的事情。我尝试使用您的代码重现您的问题,但我无法。您的四按钮对我有效(它引发单击事件,然后执行我的命令)。为什么你认为点击事件没有被触发?当我点击我的任何一个按钮时,什么都没有发生-甚至连一个点击的动画也没有,我的消息框也没有弹出。。。
<custom:QuadButton Size="200" DisplayText="Administration" ImageSource="../Pictures/Users.png" ExecuteCommand="{Binding VM.TestButton}"/>