WPF StackPanel为何不响应MouseDown事件?
程序员文章站
2022-06-11 08:30:50
...
<StackPanel Grid.Column="1" Margin="40,40,20,40" MouseDown="StackPanel_MouseDown" TouchDown="StackPanel_TouchDown">
但是不管怎么弄,MouseDown事件都没响应。后来总算了解到:
在WPF中Canvas、StackPanel如果不设置背景颜色(Background)属性,就会出现无法获取鼠标焦点的情况。
改为:
<StackPanel Grid.Column="1" Margin="40,40,20,40" MouseDown="StackPanel_MouseDown" TouchDown="StackPanel_TouchDown" Background="#00FFFFFF">
果然OK了。