Как сделать так, чтобы неявный scrollviewer отображался слева, а не справа - PullRequest
6 голосов
/ 15 марта 2012

У меня есть ScrollViewer, который появляется справа, когда в списке достаточно объектов.Как я могу сделать так, чтобы оно появилось на левой стороне?

<ListBox 
x:Name="MessageListBox" 
BorderThickness="0" 
ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
HorizontalContentAlignment="Stretch"  
AlternationCount="2" 
ItemContainerStyle="{StaticResource AltStyle}" 
SelectionMode="Extended" 
>
 <ListBox.ItemTemplate >
  <DataTemplate>
   <!-- button --> 
<!-- closing tags --> 

Ответы [ 3 ]

9 голосов
/ 28 марта 2014

Это может быть достигнуто путем переноса списка в ScrollViewer и изменения свойства ScrollViewer FlowDirection на «RightToLeft». Также не забудьте восстановить список FlowDirection в LeftToRight, иначе он унаследует направление родителя.

<ScrollViewer FlowDirection="RightToLeft"
    CanContentScroll="False" VerticalScrollBarVisibility="Auto">
  <ListBox ItemsSource="{Binding CustomItems}" FlowDirection="LeftToRight"/>
</ScrollViewer>

Я нашел это в социальных блогах MSDN, http://social.msdn.microsoft.com/Forums/vstudio/en-US/e796231d-5c92-44b4-bb7e-c3b74d81a99c/how-to-set-verticalscroll-bar-on-left-side?forum=wpf

3 голосов
/ 15 марта 2012

Это достигается путем изменения шаблона ScrollViewer в ListBox.

Начните с изменения ColumnDefinitions для сетки контейнера. Затем поместите вещи в правильные столбцы.

Веселись!

<!--This should be able to be placed on any WPF Window for testing purposes-->
<ListBox Height="85" VerticalAlignment="Top" Margin="117,110,300,0">
    <ListBox.Template>
        <ControlTemplate TargetType="{x:Type ListBox}">
            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
                <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
                    <ScrollViewer.Template>
                        <ControlTemplate TargetType="{x:Type ScrollViewer}">
                            <Grid x:Name="Grid" Background="{TemplateBinding Background}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>                    
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Rectangle x:Name="Corner" Grid.Column="0" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/>
                                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="1" Margin="{TemplateBinding Padding}" Grid.Row="0"/>
                                <ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="0" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Grid.Row="0" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"/>
                                <ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Orientation="Horizontal" Grid.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
                            </Grid>
                        </ControlTemplate>
                    </ScrollViewer.Template>
                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </ScrollViewer>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                </Trigger>
                <Trigger Property="IsGrouping" Value="true">
                    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </ListBox.Template>
    <TextBox Text="Hi Mom!"/>
    <TextBox Text="Hi Dad!"/>
    <TextBox Text="Hi Father!"/>
    <TextBox Text="Hi Mother!"/>
    <TextBox Text="Hi Padre!"/>            
</ListBox>

p.s. Если вы хотите переместить HorizontalScrollBar, просто измените порядок RowDefinitions, выполните то же упражнение (поместите каждый дочерний компонент в соответствующую строку)

0 голосов
/ 10 ноября 2017

Просто установите для встроенного средства прокрутки ListBox значение RightToLeft:

<ListBox ScrollViewer.FlowDirection="RightToLeft" />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...