流体列表框上的水平滚动条

发布于 2024-10-25 10:48:17 字数 2691 浏览 4 评论 0原文

我想要什么:让该死的水平滚动条出现。我将对其进行一些编辑,以便适合应用程序的其余样式方案,但不会太多。

我拥有的

这是目前列表框的代码。除了滚动条不出现之外,一切都运行完美。你可能会说......“好吧,你在任何地方都没有滚动查看器”,但我已经尝试在很多地方插入滚动查看器,但仍然没有运气。

列表框代码:

<ListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource itemsdatatemplate}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" ItemsPanel="{StaticResource HorizontalListBoxTemplate}" ItemContainerStyle="{StaticResource TransparentListBox}" VerticalAlignment="Center" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />

'TransparentListBox'(关闭选定的背景颜色):

<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Grid>
                    <Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                    <Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                        <ContentPresenter></ContentPresenter>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

水平列表框(使列表框水平,而不是标准垂直)

<ItemsPanelTemplate x:Key="HorizontalListBoxTemplate">
    <StackPanel Orientation="Horizontal">
    </StackPanel>
</ItemsPanelTemplate>

数据模板(实际显示项目)

<DataTemplate x:Key="itemsdatatemplate">
        <local:ListItemControl HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding}"/>
</DataTemplate>

我有一种感觉,这将是一个简单的添加,但提前致谢。

更新

看起来滚动条现在确实出现了:

    <Style x:Key="ScrollingListBox" TargetType="ListBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <ScrollViewer HorizontalScrollBarVisibility="Visible">
                            <ItemsPresenter></ItemsPresenter>
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

但它们没有相应的功能。他们感觉……破碎了。但是,如果要定义网格的静态宽度(例如 300),则 ScrollViewer 的效果非常好。现在我有一个完全流畅的布局(意味着东西会拉伸以填充),这对于滚动查看器来说是不可接受的吗?

What I want: To get the darn horizontal scrollbar to appear. I will be editing it a bit just so i fits the rest of the app's style scheme, but not too much.

What I have

Here is the code for the listbox as of now. Everything runs perfectly except the scrollbars dont appear. You might say... "well you dont have a scrollviewer anywhere", but I have tried inserting a scrollviewer in numerous places and still no luck.

The Listbox Code:

<ListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource itemsdatatemplate}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" ItemsPanel="{StaticResource HorizontalListBoxTemplate}" ItemContainerStyle="{StaticResource TransparentListBox}" VerticalAlignment="Center" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />

The 'TransparentListBox' (to shut-up the selected background color):

<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Grid>
                    <Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                    <Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                        <ContentPresenter></ContentPresenter>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Horizontal List Box (to make the listbox Horizontal, rather than standard vertical)

<ItemsPanelTemplate x:Key="HorizontalListBoxTemplate">
    <StackPanel Orientation="Horizontal">
    </StackPanel>
</ItemsPanelTemplate>

The Datatemplate (to actually show the Items)

<DataTemplate x:Key="itemsdatatemplate">
        <local:ListItemControl HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding}"/>
</DataTemplate>

I have a feeling its going to be a simple addition, but Thanks in advance.

Update

It looks like the scrollbars now do appear with this:

    <Style x:Key="ScrollingListBox" TargetType="ListBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <ScrollViewer HorizontalScrollBarVisibility="Visible">
                            <ItemsPresenter></ItemsPresenter>
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

But they do not function accordingly. They feel... broken. However, if one was to define a static width (say 300) of the grid, then the ScrollViewer acts perfectly. Right now I have a completely fluid layout (meaning things stretch to fill), is this not acceptable for scrollviewers?

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

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

发布评论

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

评论(1

为你鎻心 2024-11-01 10:49:21

当您创建自己的模板时,您必须在其中定义 ScrollViewer 并使用 ItemPresenter 而不是 ContentPresenter。

<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Grid>
                    <Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                    <Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                        <ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Visible">
                            <ItemsPresenter />
                        </ScrollViewer>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

When you create your own template, you have to define the ScrollViewer in there and use an ItemPresenter instead of a ContentPresenter.

<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Grid>
                    <Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                    <Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                        <ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Visible">
                            <ItemsPresenter />
                        </ScrollViewer>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文