none
Canvas只有IsManipulationEnabled="True",其上面的button点击事件就不能响应?? RRS feed

  • 问题

  • <Window x:Class="Test.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="win_loaded">
        <Grid>
            <Border Width="300" Height="100" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Canvas x:Name="ButtonCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  IsManipulationEnabled="True">
                   </Canvas>
            </Border>
               </Grid>
    </Window>
    
    Canvas只有IsManipulationEnabled="True",其上面的button点击事件就不能响应??
    2014年9月1日 10:55

全部回复

  • 触摸屏下只要设置Canvas的IsManipulationEnabled为true,上面的按钮就不响应click事件,求助,怎么解决??
    2014年9月1日 10:59
  • 楼主 你好,

    需要让Canvas能够接收Click事件,需要给Canvas设置一个背景色。默认情况下Canvas的背景色为Null,不能接受相应的Click事件。另外这里指的Click事件应该是一些MouseLeftDown/Up之类的事件,因为Canvas本身并没有Click事件。

    	<Canvas x:Name="ButtonCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  IsManipulationEnabled="True" Background="Transparent"
    			MouseLeftButtonDown="ButtonCanvas_MouseLeftButtonDown">
    	</Canvas>

    谢谢!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年9月2日 1:23
    版主
  • 你好

    你所说的不是我问的问题。我是在这个Canvas上面加入了button。我是指这个button的click事件

    <Window x:Class="Test.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="win_loaded">
        <Grid>
            <Border Width="300" Height="100" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Canvas x:Name="ButtonCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  IsManipulationEnabled="True" Background="Transparent">
                    <Button  Width="80" Background="AliceBlue" Height="100" Click="btn_clik"/>
                    <Label x:Name="label" Content="xxx" Width="100" Height="100" Canvas.Left="100"/>
                </Canvas>
            </Border>
    
        </Grid>
    </Window>
    

    像这样button的点击事件Click="btn_clik"鼠标下是可以的,但是程序运行在触控设备手指点击按钮,Click="btn_clik"事件就不能响应

    但是,像下面这样:

    <Window x:Class="Test.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="win_loaded">
        <Grid>
            <Border Width="300" Height="100" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Canvas x:Name="ButtonCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  IsManipulationEnabled="False" Background="Transparent">
                    <Button  Width="80" Background="AliceBlue" Height="100" Click="btn_clik"/>
                    <Label x:Name="label" Content="xxx" Width="100" Height="100" Canvas.Left="100"/>
                </Canvas>
            </Border>
    
        </Grid>
    </Window>
    

    只要IsManipulationEnabled="False",用鼠标点击按钮,或者是在触控设备上用手指点击按钮,点击事件都能响应,

    IsManipulationEnabled="True"时,触控设备上用手指点击就不能响应button按钮的点击事件

    2014年9月3日 8:45