首页 > 其他 > 详细

WPF中的DataTemplate

时间:2014-02-27 17:16:31      阅读:531      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
<Window x:Class="DateTemplate应用.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DateTemplate应用"
        xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <!--DataTemplate-->
        <DataTemplate DataType="{x:Type local:Unit}">
            <Grid>
                <StackPanel Orientation="Horizontal">
                    <Grid>
                        <Rectangle Stroke="Yellow" Fill="Orange" Width="{Binding Price}"/>
                        <TextBox Text="{Binding Year}"/>
                    </Grid>
                    <TextBlock Text="{Binding Price}" Margin="5,0"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
        <!--数据源-->
        <collections:ArrayList x:Key="ds">
            <local:Unit Year="2001" Price="100"/>
            <local:Unit Year="2002" Price="120"/>
            <local:Unit Year="2003" Price="140"/>
            <local:Unit Year="2004" Price="160"/>
            <local:Unit Year="2006" Price="180"/>
            <local:Unit Year="2008" Price="200"/>
        </collections:ArrayList>
    </Window.Resources>
    <StackPanel>
        <ListBox ItemsSource="{StaticResource ds}"/>
        <ComboBox ItemsSource="{StaticResource ds}"/>
    </StackPanel>
</Window>
bubuko.com,布布扣

bubuko.com,布布扣

以XML数据格式来显示

WPF中的DataTemplate,布布扣,bubuko.com

WPF中的DataTemplate

原文:http://www.cnblogs.com/chenyongblog/p/3569972.html

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