zoukankan      html  css  js  c++  java
  • wpf之ListBox横向显示所有ListBoxItem

    Xaml:

    <Window x:Class="WpfApplication6.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <ListBox x:Name="lb">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name}" Margin="2"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Window>
    View Code

    C#:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication6
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                Person p1 = new Person { Name="张三",Age=19};
                Person p2 = new Person { Name = "李四", Age = 19 };
                Person p3 = new Person { Name = "王五", Age = 19 };
                List<Person> list = new List<Person>();
                list.Add(p1);
                list.Add(p2);
                list.Add(p3);
                lb.ItemsSource = list;
            }
        }
    
        public class Person
        {
            private string name;
    
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
    
            private int age;
    
            public int Age
            {
                get { return age; }
                set { age = value; }
            }
    
        }
    }
    View Code

    运行效果:

  • 相关阅读:
    java环境配置为1.7jdk为什么cmd java -version查看版本是1.8
    bulid path 引 jar包 步骤
    eclipse 报错
    PLSQL使用技巧
    Oracle sqlplus不是内部或外部命令
    SVN 插件安装到Myeclipse10 上(经典)
    socket学习
    Eclipse 配置 插件svn 包步骤
    如何在Eclipse中使用SVN(经典)
    linux 下搭建LAMP
  • 原文地址:https://www.cnblogs.com/527289276qq/p/4831221.html
Copyright © 2011-2022 走看看