仅带有按钮的 Silverlight Scrollviewer

2024-04-17

我使用 ScrollViewer 作为 Silverlight 应用程序的一部分。它具有水平方向,我希望它显示为仅显示滚动按钮,而不显示滚动条本身。像这样粗略的 ASCII 渲染:

------------------------------------------------------
|   |                                            |   |
| < |                Content Here                | > |
|   |                                            |   |
------------------------------------------------------

我知道我可以使用模板功能,但我见过的所有示例都只会改变所有元素的外观,而不是它们的原始定位,或者它们是否出现。是否可以做到这一点,有人可以提供模板的概要吗?


这是另一种选择。覆盖 SCrollviewer 的默认模板并将按钮处理为 PageUp/PageDown。我下面的例子是一个垂直滚动的滚动查看器。您可以轻松更改为水平滚动,并将处理程序从 PageUp/PageDown 更改为 Left 和 Right 处理程序。

<ControlTemplate TargetType="{x:Type ScrollViewer}" x:Key="ButtonOnlyScrollViewer">
        <ControlTemplate.Resources>
            <!-- Add style here for repeat button seen below -->
        </ControlTemplate.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <RepeatButton Grid.Row="0"
                          Foreground="White" 
                          Background="Yellow" 
                          HorizontalAlignment="Stretch" 
                          Command="ScrollBar.PageUpCommand"
                          Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}">
            </RepeatButton>

            <ScrollContentPresenter
                CanContentScroll="{TemplateBinding CanContentScroll}"
                Grid.Row="1" 
                Content="{TemplateBinding Content}"  
                Width="{TemplateBinding Width}"
                Height="{TemplateBinding Height}" 
                Margin="{TemplateBinding Margin}"/>

            <RepeatButton Grid.Row="2" Background="Black" Foreground="White" Command="ScrollBar.PageDownCommand">
            </RepeatButton>
        </Grid>
    </ControlTemplate>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

仅带有按钮的 Silverlight Scrollviewer 的相关文章

随机推荐