WPF中ListBox的WrapPanel布局「建议收藏」

WPF中ListBox的WrapPanel布局「建议收藏」WPF中ListBox的WrapPanel布局,如果排出来是纵向列表,原因是Theme错了。

大家好,又见面了,我是你们的朋友全栈君。

ListBox_WrapPanel

<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfDemo" x:Class="WpfDemo.InputBar" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="360">
    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border Margin="5"/>
            </DataTemplate>
        </ListBox.ItemTemplate>

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBoxItem Width="100" Height="100" Margin="5" Content="1"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="2"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="3"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="4"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="5"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="6"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="7"/>
        <ListBoxItem Width="100" Height="100" Margin="5" Content="8"/>
        
    </ListBox>
</UserControl>

======================================================

如果排出来是纵向列表,原因是Theme错了

如我用的ExpressionDark.xaml作为Theme,修改710行

<StackPanel Margin="1,1,1,1" IsItemsHost="true" />

改为

<ItemsPresenter Margin="1,1,1,1"/>

参考出处:
http://stackoverflow.com/questions/4244793/listbox-not-showing-items-horizontally-after-using-theme

另外CodeProject上一文也可以参考:http://www.codeproject.com/Articles/18561/Custom-ListBox-Layout-in-WPF

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/163314.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • APT防御_简述对安全的理解

    APT防御_简述对安全的理解在信息化的时代,很多业务都依赖于互联网,例如说网上银行、网络购物、网游等。大量的数据依赖于网络。无疑Web成为领导者。随着国家安全法的不断完善,企业及公司对用户隐私以及公司的重要信息逐渐加强重视。也使得暴露在网络上的Web面临更高的挑战。这种黑白交替的时代,黑白技术在对抗中也在不断的发展。也使得安全测试逐渐规范化。作为新人,浅谈一下Web安全观。浅谈从Web安全到APT防御。一、web系统存在的安全性复杂应用系统代码量大、开发人员出现疏忽;系统屡次升级、人员频繁变更,使得代码存在差别;新旧资源存在

    2022年9月19日
    2
  • java之Scanner详解「建议收藏」

    java之Scanner详解「建议收藏」1.包:importjava.util.Scanner2.使用方法:Scannerreader=newScanner(System.in);  然后reader对象调用下列方法(函数),读取用户在命令行输入的各种数据类型:   nextByte(),nextDouble(),nextFloat,nextInt(),nextLine(),nextLong(),next

    2022年7月20日
    13
  • 解决Execution failed for task ‘:app:checkDebugDuplicateClasses‘.

    解决Execution failed for task ‘:app:checkDebugDuplicateClasses‘.

    2021年10月2日
    54
  • Ubuntu 卸载 postgresql「建议收藏」

    Ubuntu 卸载 postgresql「建议收藏」文章目录Ubuntu卸载postgresqlUbuntu卸载postgresql删除相关安装sudoapt-get–purgeremovepostgresql\*删除配置及相关文件sudorm-r/etc/postgresql/sudorm-r/etc/postgresql-common/sudorm-r/var/lib/postgresql/删除用户和所有组sudouserdel-rpostgressudogroupdelp

    2022年5月7日
    548
  • idea配置Tomcat时没有Artifacts选项

    idea配置Tomcat时没有Artifacts选项首先解释一下IDEA中的Artifact是什么?Artifacts是maven中的一个概念,表示某个module要如何打包,例如warexploded、war、jar、ear等等这种打包形式;好奇这个带不带exploded的有什么差别不?exploded在这里你可以理解为展开,不压缩的意思。也就是war、jar等产出物没压缩前的目录结构。这个是不带exploded的。和下图的框框对比下,就可以看到差别啦这两张图,意在说明,带exploded和不带的差别,一个是打包压缩,另.

    2022年10月18日
    3
  • ubuntu14.04 Markdown编辑器推荐之Remarkable[通俗易懂]

    ubuntu14.04 Markdown编辑器推荐之Remarkable

    2022年1月28日
    107

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号