2012-03-15 8 views
6

十分なオブジェクトがリストにあるときに右側に表示される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 --> 
+1

私は反対側にこれを移動する警告します。通常の実装は右側になり、左側に置くとユーザーが混乱するかもしれません。 – tsells

答えて

3

これは、ListBoxのScrollViewerのテンプレートを変更することで実現します。

まず、コンテナグリッドの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. Horizo​​ntalScrollBarを移動したい場合は、RowDefinitionsを並べ替えるだけです(すべての子コンポーネントを適切な行に配置します)

+0

スクロールバーが表示されますが、スクロールしてもデータはスクロールしません – 0x4f3759df

+0

ええ、リストボックスを使用していたことに気付きました。正しくポストを編集したので、前にあったアイテムプレゼンターが使用されていることを確認してください。 – Jeremiah

+0

そして今私はあなたがWPFにいるのを見ます...もっと変化が来ています。 – Jeremiah

9

リストをScrollViewerにラップして、ScrollViewerプロパティFlowDirectionを "右から左に"。また、リスト 'FlowDirectionをLeftToRightにリストアすることを忘れないでください。そうでなければ、親の方向を継承します。私は、MSDNの社会ブログにそれを見つけた

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

http://social.msdn.microsoft.com/Forums/vstudio/en-US/e796231d-5c92-44b4-bb7e-c3b74d81a99c/how-to-set-verticalscroll-bar-on-left-side?forum=wpf

+0

これは、SrollViewerにあるコントロールの内容を逆転させます。あなたがそれを考慮しないと、それは非常に有害な影響を与える可能性があります。 – claudekennilol

+2

@claudekennilol - 実際には、これはFlowDirectをリストボックス内のLeftToRightに戻しているため、完全に機能します。アイテムがたくさんある場合は、それらをすべてグリッドの内側にラップすることもできます。 –

+1

@AnthonyNicholsそうです、この*例はそうしていると指摘しておきますが、全体的に何をするのか分からない人を指摘するのは良いことです。 – claudekennilol

0

だけrightToLeftのにListBoxコントロールの組み込みScrollViewerのを設定します。

<ListBox ScrollViewer.FlowDirection="RightToLeft" /> 
関連する問題