Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB WPF中未调用鼠标事件,z顺序是否重要?_Wpf_Vb.net - Fatal编程技术网

VB WPF中未调用鼠标事件,z顺序是否重要?

VB WPF中未调用鼠标事件,z顺序是否重要?,wpf,vb.net,Wpf,Vb.net,谷歌有很多解释,但我仍在努力实现鼠标事件 我曾尝试在画布属性中使用MouseEnter=“Canvas1\u MouseEnter”,但不起作用 我试图手动添加。它不起作用 我还尝试使用AddHandler Canvas1.MouseEnter,AddressOf Canvas1\u MouseEnterinPrivate Sub-main\u Loaded(发送方作为对象,e作为routedEventTargets)处理main.Loaded方法,它也不起作用 然后我尝试将AddHandle

谷歌有很多解释,但我仍在努力实现鼠标事件

  • 我曾尝试在画布属性中使用
    MouseEnter=“Canvas1\u MouseEnter”
    ,但不起作用
  • 我试图手动添加。它不起作用
  • 我还尝试使用
    AddHandler Canvas1.MouseEnter,AddressOf Canvas1\u MouseEnter
    in
    Private Sub-main\u Loaded(发送方作为对象,e作为routedEventTargets)处理main.Loaded方法,它也不起作用
  • 然后我尝试将
    AddHandler Canvas1.MouseEnter,Canvas1_MouseEnter的地址
    移动到
    MainWindow.g.I.vb
    文件中的
    Public Sub-InitializeComponent()
    。它不起作用
我不知道如何实现鼠标事件:(

因此,我尝试将
MouseEnter
实现为它自己的形式,正确调用事件

这是否意味着z阶问题

这是xaml文件

<Window x:Name="main" x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="620.242" Width="827.423">
    <Grid HorizontalAlignment="Left" Height="575" Margin="10,10,0,0" VerticalAlignment="Top" Width="807">
        <Canvas x:Name="Canvas1" HorizontalAlignment="Left" Height="555" Margin="794,368,-774,-348" VerticalAlignment="Top" Width="787" />
    </Grid>

</Window>
如何在画布上实现鼠标事件?
感谢您的帮助:)

WPF中的UI元素不会在其渲染区域之外接收鼠标事件(没有鼠标捕获)。除非为其
Background
属性定义非空值,否则面板(如画布)不会呈现其子元素区域之外的任何内容

您可以为画布设置
背景,如下图所示,使其使用透明笔刷渲染由其实际宽度和实际高度定义的整个区域:

<Canvas x:Name="Canvas1" Background="Transparent"
        MouseEnter="Canvas1_MouseEnter" ... />

您的画布没有MouseEnter事件。像这样使用它

<Grid>
    <Canvas HorizontalAlignment="Left" Height="158" Margin="191,85,0,0" VerticalAlignment="Top" 
            Width="221" Background="#FF575757" MouseEnter="Canvas_MouseEnter"/>
</Grid>

实际上,我确实给了鼠标事件属性。。。但问题是,我没有给出
background
属性,而您给出了元素的背景。。。谢谢,这个也有用!就这样。。。这就是解决我的问题。。。非常感谢你!!
<Grid>
    <Canvas HorizontalAlignment="Left" Height="158" Margin="191,85,0,0" VerticalAlignment="Top" 
            Width="221" Background="#FF575757" MouseEnter="Canvas_MouseEnter"/>
</Grid>
Private Sub Canvas_MouseEnter(sender As Object, e As MouseEventArgs)
    MessageBox.Show("Hello?")
End Sub