【发布时间】:2017-12-06 18:56:02
【问题描述】:
我正在尝试制作一个滚动查看器,其中滚动按钮仅在窗口尺寸太小而无法显示所有内容时才可见。我已将一些按钮放入滚动查看器中的堆栈面板中。
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>
<RowDefinition Height="20"/>
<RowDefinition/>
</Grid.RowDefinitions>
<RepeatButton x:Name="LineLeftButton"
Grid.Column="0"
Grid.Row="0"
Command="{x:Static ScrollBar.LineDownCommand}"
Background="{StaticResource uparrow}"
CommandTarget="{Binding ElementName=scrollViewer}"/>
<RepeatButton x:Name="LineRightButton"
Grid.Column="0"
Grid.Row="2"
Background="{StaticResource downarrow}"
Command="{x:Static ScrollBar.LineUpCommand}"
CommandTarget="{Binding ElementName=scrollViewer}"/>
<ScrollViewer Grid.Column="1" Grid.Row="1" x:Name="scrollViewer"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden">
<StackPanel Orientation="Vertical">
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
<Button Width="150" Height="20"/>
</StackPanel>
</ScrollViewer>
</Grid>
滚动正在工作,但是当堆栈中没有足够的元素以至于不需要滚动时,如何禁用它?
【问题讨论】:
-
我不想要滚动条。我只需要滚动按钮在需要时可见
-
抱歉我误会了
-
没关系,你有蚂蚁建议我如何根据要求在我的代码中隐藏重复按钮
-
请检查我的答案
标签: c# wpf scrollviewer