zoukankan      html  css  js  c++  java
  • WPF ItemsPanelTemplate

    用以定义集合控件的容器外观,如ListBox,Combox 等等
    使用一个自定义的ListBox用以说明,其默认外观是上下排列,这里修改成横向排列

    <Window.Resources>
        <DataTemplate x:Key="PersonDataTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Name}"></TextBlock>
                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Age}"></TextBlock>
                <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Hometown}"></TextBlock>
            </Grid>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="PersonItemsPanelTemplate">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"></StackPanel>
        </ItemsPanelTemplate>
    </Window.Resources>
    <Grid>
        <ListBox ItemsSource="{Binding}" ItemTemplate="{StaticResource PersonDataTemplate}" ItemsPanel="{StaticResource PersonItemsPanelTemplate}"></ListBox>
    </Grid>
    

    定义一个ItemsPanelTemplate,设置方向为Horizontal
    在ListBox中指定ItemsPanel

    效果

     


    常见的条目控件有:ListBox,Menu,StatusBar等(默认纵向排列)

    示例代码

    https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/Template/ItemsPanelTemplate

  • 相关阅读:
    浅谈隔板法
    最短路spaf及dijkstra模板
    P1219 最优贸易
    P1211 街道赛跑
    图结构模板
    P1218 过路费
    使用Asp.net Identity 创建用户 、登录代码
    asp.net identity 介绍
    响应式图像
    glyphicon 图标的使用
  • 原文地址:https://www.cnblogs.com/Lulus/p/8157714.html
Copyright © 2011-2022 走看看