在以下代码中,Scrollbar控件不会显示,但Slider控件会显示.如果我将Scrollbar控件更改为Slider控件只需将Scrollbar更改为Slider就可以完美地运行,但是我更喜欢滚动条控件在应用程序滑块上的外观.
我手动使用Win2D将大型1000格x 1000单元网格绘制到动画画布中,但仅使用滚动条(滑块)位置显示滚动到的部分.
使用Slider控件时可以正常工作.
<Page
x:Class="TrappedEditor.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TrappedEditor"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
Unloaded="Page_Unloaded"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" SizeChanged="Grid_SizeChanged">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<ScrollBar x:Name="scrollBarVertical" Visibility="Visible" Grid.Row="0" Grid.Column="1" ValueChanged="scrollBarVertical_ValueChanged" Orientation="Vertical" Minimum="0" Maximum="1000"/>
<Slider x:Name="scrollBarHorizontal" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Orientation="Horizontal" ValueChanged="scrollBarHorizontal_ValueChanged" Minimum="0" Maximum="1000"/>
<canvas:CanvasAnimatedControl Grid.Row="0" Grid.Column="0" x:Name="canvas" Draw="canvas_Draw" CreateResources="canvas_CreateResources"/>
</Grid>
最佳答案 解决了这个问题.添加IndicatorMode =“MouseIndicator”会按预期显示ScrollBar.
例如:
<ScrollBar x:Name="scrollBarVertical" IndicatorMode="MouseIndicator" Visibility="Visible" Grid.Row="0" Grid.Column="1" ValueChanged="scrollBarVertical_ValueChanged" Orientation="Vertical" Minimum="0" Maximum="1000"/>