如何在WPF c#中绑定一个有Mousedown事件的键下边界

本文关键字:Mousedown 一个 事件 边界 WPF 绑定 | 更新日期: 2023-09-27 18:09:59

我有一个边框:

<Border x:Name="butborder1" BorderThickness="1" Grid.Row="0" CornerRadius="0,10,10,0" 
 BorderBrush="Black" Margin="0,98,33,0" Height="41" VerticalAlignment="Top" 
 HorizontalAlignment="Right" Width="87" IsEnabled="False" MouseUp="butborder1_MouseUp" 
 KeyDown="butborder1_KeyDown">

它有一个MouseUp事件:

private void butborder1_MouseUp(object sender, MouseButtonEventArgs e){
        butborder5.Visibility = Visibility.Visible;
        rotate.Visibility = Visibility.Visible;
        butborder4.Visibility = Visibility.Visible;
        image2.Visibility = Visibility.Visible;
        butborder1.Visibility = Visibility.Hidden;
        image4.Visibility = Visibility.Hidden;
        butborder2.Visibility = Visibility.Hidden;
        image3.Visibility = Visibility.Hidden;
        butborder3.Visibility = Visibility.Hidden;
        image1.Visibility = Visibility.Hidden;
        SetInput(true);
        butin(false);
        butborder4.IsEnabled = true;}

我想绑定一个keydown事件,但它不工作:

private void butborder1_KeyDown(object sender, KeyEventArgs e){
    if (e.Key == Key.Insert)
    {
        butborder1_MouseUp(null,null);
    }
}

简单:

我有一个边界,就像我的WPF表单上的按钮,它有一个鼠标up事件,工作完美,我的用户想按下一个键,而不是点击那个按钮,所以我应该给它一个KeyDown事件…但是KeyDown事件不能调用MouseUp事件…

如何在WPF c#中绑定一个有Mousedown事件的键下边界

你的问题很宽泛,所以试试这个。我认为这应该调用函数butborder1_MouseUp(null,null);

private void butborder1_KeyDown(object sender, KeyEventArgs e){
    // This is not always true.
    //if (e.Key == Key.Insert)
    //{
        butborder1_MouseUp(null,null);
    //}
}
相关文章: