滚动视图阻塞事件

4

我今天要解决的问题是ScrollViewer,以及它阻塞我的事件。下面是一些XAML代码:

    <ScrollViewer x:Name="scrollv" Panel.ZIndex="15" Margin="8,65.5,0,22" VerticalScrollBarVisibility="Visible" Height="392.5" Background="White" IsHitTestVisible="False">
        <Grid x:Name="listaintrebari" Height="Auto" Width="301.5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="White" >

        </Grid>

    </ScrollViewer>

问题是这样的:在滚动视图器中的网格上,我通过编程添加了一个问题用户控件...其中包含一个带有点击事件的按钮。我的问题是,我无法点击该按钮...就好像滚动视图器像一个隐形屏障保护着用户控件和按钮以免受到鼠标的侵害!

任何帮助都将不胜感激!

编辑:(这是我的问题用户控件)

   <UserControl
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:eHelper_v3"
mc:Ignorable="d"
x:Class="eHelper_v3.questions"
x:Name="IntrebareControl" Width="330.641" Margin="0" MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"

>

<Grid x:Name="LayoutRoot" ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="0,0,13,0" Height="90" >
    <Rectangle x:Name="rect" Panel.ZIndex="20" Height="90" Stroke="#FF0975A3"  >
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#1404BFD8" Offset="0.004"/>
                <GradientStop Color="#1300A7FF" Offset="0.996"/>
                <GradientStop Color="#2B0F82CC" Offset="0.459"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Image x:Name="imagine" HorizontalAlignment="Left" Margin="8,8,0,8" Width="126.667" Stretch="Fill" MouseLeftButtonDown="imagine_MouseLeftButtonDown" />
    <TextBlock x:Name="textul" Margin="138.667,8,8,22.5" TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" FontSize="9.333"/>
    <Label x:Name="status" Content="Status" Height="22" Margin="127,0,100,0.5" VerticalAlignment="Bottom" FontSize="9.333" Background="#00894848" Foreground="Red"/>
    <Button x:Name="raspundeBtn" Content="Raspunde" HorizontalAlignment="Right" Height="18" Margin="0,0,8,4.5" VerticalAlignment="Bottom" Width="50.974" FontSize="9.333" Click="raspundeBtn_Click"/>

</Grid>

重新编辑...插入了错误的代码...这里有点困

3个回答

5

也许您的按钮前面有一些控件。要“穿过”控件单击,您可以使用

IsHitTestVisible="false"

您能发布您的CommentThat吗?

@在您的编辑后: 似乎您的RichTextBox和FlowDocument覆盖了按钮。 将按钮作为Grid的最后一个子元素添加。


0
用户控件正在处理左键单击事件,因此单击事件无法传递到内容。
    MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"

那个事件被触发了吗?


没有任何异常被抛出。我有一些应该弹出的消息框,但是什么也没有显示。 - ALex Popa

0

以防万一,如果有人也遇到了 ScrollViewer 阻止鼠标按钮事件触发的问题,我通过为相应的 UIElement 设置 ZIndex 来解决了这个问题:

<TextBlock Text="Hello World!" Panel.ZIndex="2" MouseLeftButtonUp="TextBlockMouseLeftButtonUp"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接