canvas的鼠标事件为什么没有响应

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="350" Width="525" >






private void canvas4_MouseDown(object sender, MouseButtonEventArgs e)
{
double mouseX = 100;
double Height = canvas4.Height;
Line line1 = new Line();
line1.X1 = mouseX;
line1.Y1 = 0;
line1.X2 = mouseX;
line1.Y2 = Height;
line1.StrokeThickness = 0.5;
line1.Stroke = System.Windows.Media.Brushes.Blue;
canvas4.Children.Add(line1);
}

2个回答

我想知道canvas这种单击事件应该怎么做,难道它不能做吗?我也是初学者,求大神指导

我找到了,把事件定义到windows窗口下,鼠标事件就可以响应了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问