我想在我的应用程序中实现一些秘密功能,并且只能通过ctrl左键单击按钮的下半部分来调用它们。这可能在WPF中实现吗?我试图创建一个演示应用程序,并且调试不会在单击事件处理程序中向我显示光标位置信息。以下是我的测试代码。有任何想法吗?如何仅在用户按下按钮的下半部时触发事件?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="255.284" Width="313.918">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="81,89,0,0" VerticalAlignment="Top" Width="158" Height="49" Click="button_Click"/>
</Grid>
</Window>
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{ // <----- set break point here, can't find cursor info in e and sender
}
}
}
我不知道这是一个干净的方式来做到这一点.... –
为什么不呢? OP在单击GUI上的某个区域时需要特殊功能。这听起来像一个按钮的工作。 – user2647513
我可能会工作,但如果你可以做到这一点,而无需添加新的(隐藏的)UI元素,对我来说它更清洁 –