Scrollviewer阻止事件

时间:2012-03-12 20:19:49

标签: c# wpf scrollviewer routedevents

我今天正在与之斗争的是滚动浏览器,以及它阻止我的事件的事实。这里有一些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的问题......其中有一个带有点击事件的按钮。我的问题是我无法设法点击按钮..就像是scrollviewer就像一个看不见的盾牌,保护用户控制和按钮免受邪恶的鼠标!

任何有帮助的帮助!

编辑:(这是我的问题Usercontrol)

   <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>

REEDITED ...错误的代码插入......有点困在这里

3 个答案:

答案 0 :(得分:3)

也许,某些控件就在你的按钮前面。要点击“通过”控件,您可以使用

IsHitTestVisible="false"

你能发表你的评论吗?

@after你的编辑: 看起来你的RichTextBox和FlowDocument位于Button上。 将Button添加为Grid的最后一个子项。

答案 1 :(得分:0)

用户控件正在处理鼠标左键,因此点击无法访问内容。

    MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"

该事件是否会被提升?

答案 2 :(得分:0)

如果有人也有ScrollViewer阻止鼠标按钮事件触发的问题,我可以通过为相应的UIElement设置ZIndex来解决此问题:

# Sanity check - Modular [remainder] divison in loops
# Python Libraries 
from random import randint
# Create a list of 50 random integers between 0 and 1000
randomNumbers = []
for i in range(100): 
    randomInt = randint(0, 1000) 
    randomNumbers.append(randomInt)
print("List of 50 values: ", randomNumbers,"\n") 

##########################################################
# METHOD 1: Remove odd numbers - New list based
newList     = [x for x in randomNumbers if x % 2 == 0]
print('List comprehension method...')
print('\t > List length = '+str(len(newList)))
print(newList)
print('\n')

# METHOD 2: Keep even numbers - Loop Based
evenList = []
for i in randomNumbers:
    if i % 2 == 0:
        evenList.append(i)
print("List append method...")
print('\t > List length = '+str(len(evenList)))
print(evenList)
print('\n')

# METHOD 3: Remove odd numbers - Loop Based
counter     = 0
# > Loop 1
for i in randomNumbers: 
    if i % 2 != 0:
        randomNumbers.remove(i)
counter += 1
print("Loop run: "+str(counter))
print('\t > List length = '+str(len(randomNumbers)))
print(randomNumbers)
# > Loop 2
for i in randomNumbers: 
    if i % 2 != 0:
        randomNumbers.remove(i)
counter += 1
print("Loop run: "+str(counter))
print('\t > List length = '+str(len(randomNumbers)))
print(randomNumbers)
# > Loop 3
for i in randomNumbers: 
    if i % 2 != 0:
        randomNumbers.remove(i)
counter += 1
print("Loop run: "+str(counter))
print('\t > List length = '+str(len(randomNumbers)))
print(randomNumbers)
# > Loop 4
for i in randomNumbers: 
    if i % 2 != 0:
        randomNumbers.remove(i)
counter += 1
print("Loop run: "+str(counter))
print('\t > List length = '+str(len(randomNumbers)))
print(randomNumbers)