首页 > 代码库 > D22_01_ListView控件 GridView GridViewColumn CellTemplate Dat

D22_01_ListView控件 GridView GridViewColumn CellTemplate Dat

image

<Window x:Class="demo.AdvancedListView"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="AdvancedListView" Height="600" Width="720"        xmlns:local="clr-namespace:demo">    <Window.Resources>        <local:ImagePathConverter x:Key="ImagePathConverter"></local:ImagePathConverter>    </Window.Resources>    <Grid>        <ListView Margin="5" Name="lstProducts">            <!--更方便数据展示-->            <ListView.View>                <GridView>                    <GridView.Columns>                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=ModelName}"></GridViewColumn>                        <GridViewColumn Header="Model" DisplayMemberBinding="{Binding Path=ModelNumber}"></GridViewColumn>                        <!--GridViewColumn使用单元格模板CellTemplate->数据模板DataTemplate->再放对象如TextBlock,image-->                        <GridViewColumn Header="Description" Width="300">                            <GridViewColumn.CellTemplate>                                <DataTemplate>                                    <TextBlock Text="{Binding Path=Description}" TextWrapping="Wrap"></TextBlock>                                </DataTemplate>                            </GridViewColumn.CellTemplate>                        </GridViewColumn>                        <GridViewColumn Header="Picture">                            <GridViewColumn.CellTemplate>                                <DataTemplate>                                    <Image Source="{Binding Path=ProductImagePath,Converter={StaticResource ImagePathConverter}}"></Image>                                </DataTemplate>                            </GridViewColumn.CellTemplate>                        </GridViewColumn>                        <GridViewColumn Header="Price" DisplayMemberBinding="{Binding Path=UnitCost,StringFormat={}{0:C}}"></GridViewColumn>                    </GridView.Columns>                </GridView>            </ListView.View>        </ListView>    </Grid></Window>

AdvancedListView (窗体对应的类)

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.Shapes;namespace demo{    /// <summary>    /// AdvancedListView.xaml 的交互逻辑    /// </summary>    public partial class AdvancedListView : Window    {        public AdvancedListView()        {            InitializeComponent();            lstProducts.ItemsSource = App.StoreDb.GetProducts();        }    }}

D22_01_ListView控件 GridView GridViewColumn CellTemplate Dat