我有一个滚动条和一个滚动浏览器。
我想使用自己的滚动条滚动ScrollViewer的内容。
这是我的代码:
<StackPanel HorizontalAlignment="Stretch">
<ScrollBar
x:Name="TestScrollBar"
HorizontalAlignment="Stretch"
Orientation="Horizontal"
Scroll="TestScrollBar_Scroll"
Maximum="{Binding ElementName=TestScrollViewer, Path=ExtentWidth, Mode=OneWay}"
ViewportSize="{Binding ElementName=TestScrollViewer, Path=ViewportWidth, Mode=OneWay}"
Visibility="Visible"
Background="Aqua"/> <!--This is set for seeing when/if the ScrollBar is visible-->
<ScrollViewer
x:Name="TestScrollViewer"
ViewChanged="TestScrollViewer_ViewChanged"
HorizontalAlignment="Stretch"
HorizontalScrollMode="Auto"
HorizontalScrollBarVisibility="Auto"> <!--This is set to Auto for now, but should be Disabled/Hidden later-->
<TextBlock FontSize="144" Text="This is blind text. Ignore this completely. It is only here to fill up the ScrollViewer horizontally."/>
</ScrollViewer>
</StackPanel>
private void TestScrollBar_Scroll(object sender, ScrollEventArgs e)
{
TestScrollViewer.ChangeView(e.NewValue, null, null);
}
private void TestScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
TestScrollBar.Value = TestScrollViewer.HorizontalOffset;
}
当我运行我的应用程序时,条形图在几毫秒内可见(浅绿色闪光),之后消失。
我使用Live可视树和Live属性资源管理器检查了XAML和代码中设置的所有值,但ScrollBar不可见,即使ScrollViewer的ScrollBar可见。
1条答案
按热度按时间bwleehnv1#
您只需要将
IndicatorMode
设置为MouseIndicator
,默认情况下IndicatorMode
为None
。因此,您的
ScrollBar
代码应该如下所示: