2011-09-14 75 views
2

列表視圖的默認滾動條出現在右側。我設計了一種新的風格,並希望它與列表視圖控件分開。你在圖像中看到的是我現在如何使用混合設置它。鏈接到列表視圖的自定義簡單滾動條

那麼如何將自定義滾動條鏈接到列表視圖?我使用的是混合4

列表視圖圖片位於:

http://i141.photobucket.com/albums/r69/thebirdbath/scroll.jpg

+0

是否要應用這種風格到'ScrollViewer'的'Template'內,將其顯示在左側還是你想將它定義了'ListView'之外? –

+0

我想你也可以通過添加一個附加的行爲來「鏈接它們」,在這裏你訂閱ListView的'Loaded'事件,在事件處理程序中你可以在模板中找到'ScrollViewer',然後在他們的ScrollChanged事件。我想你還需要綁定'Minimum'和'Maximum'值 –

回答

1

我不知道,如果你想你的風格添加到ScrollViewerListViewTemplate內或者如果你想禁用該ScrollViewer並將ListView放置在單獨的ScrollViewer中。

Style適用於ScrollViewerTemplate並把ScrollBar你可以使用GridView時修改默認Template左側。這將需要參考PresentationFramework.Aero

  • ScrollViewer設置FlowDirection="RightToLeft"將其放置在左側
  • 設置FlowDirection="LeftToRight"ItemsPresenterGridViewHeaderRowPresenter,因爲他們必承受RightToLeft否則
  • 要獲得ScrollViewer和內容之間的透明空間,設置爲的Background="Transparent",並在ItemsPanel上設置所需的Background而不是
  • Padding控制透明空間,例如Padding="0,0,10,0"

貌似這個

enter image description here

<ListView xmlns:MS_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
      Padding="0,0,10,0" 
      Background="Transparent" 
      BorderThickness="0" 
      ScrollViewer.VerticalScrollBarVisibility="Visible"> 
    <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <VirtualizingStackPanel Background="White"/> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.Template> 
     <ControlTemplate TargetType="{x:Type ListView}"> 
      <MS_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true"> 
       <ScrollViewer Padding="{TemplateBinding Padding}" 
           Style="{YourStyle...}" 
           FlowDirection="RightToLeft"> 
        <ScrollViewer.Resources> 
         <Style TargetType="GridViewHeaderRowPresenter"> 
          <Setter Property="FlowDirection" Value="LeftToRight"/> 
         </Style> 
        </ScrollViewer.Resources> 
        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
            FlowDirection="LeftToRight"/> 
       </ScrollViewer> 
      </MS_Themes:ListBoxChrome> 
      <ControlTemplate.Triggers> 
       <Trigger Property="IsGrouping" Value="true"> 
        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> 
       </Trigger> 
       <Trigger Property="IsEnabled" Value="false"> 
        <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
       </Trigger> 
      </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </ListView.Template> 
    <!--...--> 
</ListView> 
0

好了,八九不離十。它的工作,但我失去了我的列標題。此外,我無法獲得酒吧和列表視圖之間的透明度。它像酒吧仍然附加,我希望他們看起來像他們是分開的。 (看到我的原始圖像鏈接)

這一直非常有幫助。差不多了!

我的代碼如下。 enter image description here

<ListView 
          AlternationCount="2" 
          Padding="0,0,10,0" 
          Shared:GridViewSort.AutoSort="True" 
          Shared:GridViewSort.ShowSortGlyph="True" 
          ItemsSource="{Binding Contents}" 
          SelectionMode="Extended" 
          Background="Transparent" 
          Foreground="White" 
          SelectionChanged="ListBoxSelectionChanged" 
          BorderThickness="0" 

          ItemContainerStyle="{DynamicResource ListViewItemStyle}" 
          Style="{DynamicResource ListViewStyle1}" Margin="0" VerticalAlignment="Top"> 

          <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <VirtualizingStackPanel Background="Transparent"/> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.Template> 
     <ControlTemplate TargetType="{x:Type ListView}"> 
      <MS_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true"> 
       <ScrollViewer Padding="{TemplateBinding Padding}" 
           Style="{DynamicResource ScrollViewerKey}" 
           FlowDirection="RightToLeft"> 
        <ScrollViewer.Resources> 
         <Style TargetType="GridViewHeaderRowPresenter"> 
          <Setter Property="FlowDirection" Value="LeftToRight"/> 
         </Style> 
        </ScrollViewer.Resources> 
        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
            FlowDirection="LeftToRight"/> 
       </ScrollViewer> 
      </MS_Themes:ListBoxChrome> 
      <ControlTemplate.Triggers> 
       <Trigger Property="IsGrouping" Value="true"> 
        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> 
       </Trigger> 
       <Trigger Property="IsEnabled" Value="false"> 
        <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
       </Trigger> 
      </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </ListView.Template> 
相關問題