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.
I’m not 100% sure how you want this
UserControlto work so I might be of target here. The way I understand it, you want to be able to do something like thisAnd the
TextBoxwill end up between the Arrow Indicators. In that case I think you’ll need to edit the Template of theUserControlinstead. Try it like thisUpdate
There are several ways which you can access the
ScrollViewerin the Template from code behind. Here’s three ways that comes to mindLoadedevent of theScrollViewerHere’s an example using the Loaded event
Code behind
And if you like to use FindName