簡體   English   中英

鼠標事件按鈕不起作用

[英]Mouse event button not working

我在WPF中有一個按鈕,正在為其創建事件處理程序。 我的目標是在單擊按鈕時產生凹陷效果。 問題是我嘗試使用其他事件處理程序,但似乎無法正常工作。 我完全看不到任何影響。 關於如何解決它的任何想法?

XAML:

<Button x:Name="btnMyAccount">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="165"/>
            <RowDefinition Height="70"/>
        </Grid.RowDefinitions>
        <Image Grid.Row="0" Source="{StaticResource Home-MyProfile}" />
        <TextBlock x:Name="txtMyAccount" Grid.Row="1" FontWeight="Bold">
            MY ACCOUNT
        </TextBlock>
    </Grid>
</Button>

C#代碼:

private void btnMyAccount_MouseDown(object sender, MouseButtonEventArgs e)
{
    btnMyAccount.BorderThickness = new Thickness(5, 5, 0, 0);
}

我認為<Button></Button>標記中包含一些內容,這意味着您現在有了按鈕的自定義模板。 您應該用<Border x:Name="yourBorder"></Border> ,然后增加邊框的思考

您必須將按鈕模板更改為如下所示:

<Button x:Name="btnMyAccount">
    <Border x:Name="yourBorder" BorderBrush="Black" BorderThickness="1">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="165"/>
                <RowDefinition Height="70"/>
            </Grid.RowDefinitions>
            <Image Grid.Row="0" Source="{StaticResource Home-MyProfile}" />
            <TextBlock x:Name="txtMyAccount" Grid.Row="1" FontWeight="Bold">
                MY ACCOUNT
            </TextBlock>
        </Grid>
    </Border>
</Button>

然后在事件處理程序中,您將更改yourBorder厚度:

private void btnMyAccount_MouseDown(object sender, MouseButtonEventArgs e)
{
    yourBorder.BorderThickness = new Thickness(5, 5, 0, 0);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM