首页 > 其他 > 详细

ItemsPanelTemplate

时间:2017-12-31 15:08:17      阅读:187      评论:0      收藏:0      [点我收藏+]

用以定义集合控件的容器外观,如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

ItemsPanelTemplate

原文:https://www.cnblogs.com/Lulus/p/8157714.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!