链接到列表视图的自定义简单滚动条

发布于 2024-12-04 18:15:12 字数 298 浏览 0 评论 0原文

列表视图的默认滚动条显示在右侧。我设计了一种新样式,希望它与列表视图控件分开显示。您在图像中看到的是我现在使用混合进行设置的方式。

那么如何将自定义滚动条链接到列表视图呢?我正在使用 Blend 4。

列表视图图像位于此处:

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

The default scrollbar for a listview appears at the right. I designed a new style and would like it to appear separate from the listview control. What you see in the image is how I have it set up now using blend.

So how do I link the custom scroll bar to the listview? I'm using Blend 4.

Listview Image located here:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

波浪屿的海角声 2024-12-11 18:15:12

我不确定您是否要将样式添加到 ListViewTemplate 内的 ScrollViewer 中,或者是否要禁用该 < code>ScrollViewer 并将 ListView 放置在单独的 ScrollViewer 中。

要将 Style 应用于 Template 中的 ScrollViewer 并将 ScrollBar 放置在左侧,您可以修改默认值使用GridView时的模板。它将需要引用 PresentationFramework.Aero

  • ScrollViewer 上设置 FlowDirection="RightToLeft" 以将其放置在左侧
  • Set ItemsPresenterGridViewHeaderRowPresenter 上的 FlowDirection="LeftToRight" 因为它们将继承 RightToLeft否则
  • 要获得 ScrollViewer 和内容之间的透明空间,请为 ListView 设置 Background="Transparent" 并设置所需的 ItemsPanel 上的背景 改为
  • 使用 Padding 控制透明空间,例如 Padding="0,0,10,0"

外观像这样

在此处输入图像描述

<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>

I'm not sure if you want to add your Style to the ScrollViewer inside the Template of the ListView or if you want to disable that ScrollViewer and place the ListView in a separate ScrollViewer.

To apply the Style to the ScrollViewer in the Template and place the ScrollBar to the left you can modify the default Template when using GridView. It will require a reference to PresentationFramework.Aero

  • Set FlowDirection="RightToLeft" on the ScrollViewer to place it on the left side
  • Set FlowDirection="LeftToRight" on the ItemsPresenter and GridViewHeaderRowPresenter since they will inherit RightToLeft otherwise
  • To get the transparent space between the ScrollViewer and the content, set Background="Transparent" for the ListView and set the desired Background on the ItemsPanel instead
  • Control the transparent space with Padding, e.g. Padding="0,0,10,0"

Looks like this

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>
梦幻的心爱 2024-12-11 18:15:12

好的,非常接近。它可以工作,但我丢失了列标题。另外,我无法获得栏和列表视图之间的透明度。就像酒吧仍然连接着一样,我希望它们看起来像是分开的。 (请参阅我的原始图像的链接)

这非常有帮助。快到了!

我的代码如下。
在此处输入图像描述

<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>

Ok, pretty close. Its working but I've lost my column headers. Also I can't get the transparency in between the bar and the listview. Its like the bar is still attached and I want them to appear like they are separate. (See the link to my original image)

This has been very helpful. Almost there!

My code is below.
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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文