为什么我的 ScrollViewer 不滚动?
我的 ScrollViewer
无法正常工作。我创建了一个 UserControl
来显示箭头指示器,告诉用户滚动查看器可以滚动。所以现在,内容刚刚溢出了 ScrollViewer
。这是我的 XAML:
<UserControl x:Class="QCK.Common.ResourceLibrary.CustomControls.ArrowScrollViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Name="UserControl">
<UserControl.Resources>
<Style x:Key="ScrollDownArror" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="2,0,18,0"/>
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=CanScrollDown}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollUpArror" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="2,0,18,0"/>
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=CanScrollUp}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<ScrollViewer Name="scrollViewer" VerticalScrollBarVisibility="Visible">
<ContentPresenter VerticalAlignment="Top"/>
</ScrollViewer>
<Border Style="{StaticResource ScrollUpArror}" DataContext="{Binding ElementName=c_list}"
IsHitTestVisible="false"
VerticalAlignment="Top">
<Image Margin="15" Height="20">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="DarkGray" Geometry="M 0, 10 L 50, 30 L 100, 10 Z">
<GeometryDrawing.Pen>
<Pen Brush="DimGray" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Border>
<Border Style="{StaticResource ScrollDownArror}" DataContext="{Binding ElementName=c_list}"
IsHitTestVisible="false"
VerticalAlignment="Bottom">
<Image Margin="15" Height="20">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="DarkGray" Geometry="M 0, 30 L 50, 10 L 100, 30 Z">
<GeometryDrawing.Pen>
<Pen Brush="DimGray" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Border>
</Grid>
</UserControl>
内容只是在控件内溢出,不显示滚动条或允许鼠标滚轮滚动或任何其他内容。
My ScrollViewer
is not working. I've created a UserControl
to show arrow indicators that tell the user that the scroll viewer can be scrolled. So now, the content just overflows the ScrollViewer
. Here is my XAML:
<UserControl x:Class="QCK.Common.ResourceLibrary.CustomControls.ArrowScrollViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Name="UserControl">
<UserControl.Resources>
<Style x:Key="ScrollDownArror" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="2,0,18,0"/>
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=CanScrollDown}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollUpArror" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="2,0,18,0"/>
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=CanScrollUp}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<ScrollViewer Name="scrollViewer" VerticalScrollBarVisibility="Visible">
<ContentPresenter VerticalAlignment="Top"/>
</ScrollViewer>
<Border Style="{StaticResource ScrollUpArror}" DataContext="{Binding ElementName=c_list}"
IsHitTestVisible="false"
VerticalAlignment="Top">
<Image Margin="15" Height="20">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="DarkGray" Geometry="M 0, 10 L 50, 30 L 100, 10 Z">
<GeometryDrawing.Pen>
<Pen Brush="DimGray" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Border>
<Border Style="{StaticResource ScrollDownArror}" DataContext="{Binding ElementName=c_list}"
IsHitTestVisible="false"
VerticalAlignment="Bottom">
<Image Margin="15" Height="20">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="DarkGray" Geometry="M 0, 30 L 50, 10 L 100, 30 Z">
<GeometryDrawing.Pen>
<Pen Brush="DimGray" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Border>
</Grid>
</UserControl>
The contents just overflow inside the control not showing a scroll bar or allowing mouse wheel scrolling or anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 100% 确定您希望这个
UserControl
如何工作,所以我可能是这里的目标。按照我的理解,您希望能够执行这样的操作并且
TextBox
将最终位于箭头指示器之间。在这种情况下,我认为您需要编辑UserControl
的模板。尝试像这样更新
您可以通过多种方式从代码隐藏中访问模板中的
ScrollViewer
。想到的三种方法ScrollViewer
的Loaded
事件添加事件处理程序下面是使用 Loaded 事件的示例
代码隐藏
如果您喜欢使用 FindName
I'm not 100% sure how you want this
UserControl
to work so I might be of target here. The way I understand it, you want to be able to do something like thisAnd the
TextBox
will end up between the Arrow Indicators. In that case I think you'll need to edit the Template of theUserControl
instead. Try it like thisUpdate
There are several ways which you can access the
ScrollViewer
in the Template from code behind. Here's three ways that comes to mindLoaded
event of theScrollViewer
Here's an example using the Loaded event
Code behind
And if you like to use FindName