首页 > 代码库 > D22_01_ListView控件 GridView GridViewColumn CellTemplate Dat
D22_01_ListView控件 GridView GridViewColumn CellTemplate Dat
<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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。