The ListView control is simple at first glance, but is actually an extremely powerful control which can be used for representing all kinds of data.
<Window x:Class="_listviewdemo.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:_listviewdemo"
Title="ListViewDemo" Height="393" Width="489" WindowStyle="SingleBorderWindow"
DataContext="{Binding RelativeSource={RelativeSource Self}}" Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="ProgressCell">
<StackPanel Orientation="Horizontal">
<ProgressBar Width="100" Height="20" Value="{Binding Progress}" ToolTip="{Binding ProgressText}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="PicCell">
<StackPanel Orientation="Horizontal">
<Image Height="50" Stretch="Uniform" Source="{Binding Pic}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListView Name="listView1">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Description" DisplayMemberBinding="{Binding Desc}" />
<GridViewColumn Width="140" Header="Progress" CellTemplate="{StaticResource ProgressCell}" />
<GridViewColumn Width="140" Header="Pic" CellTemplate="{StaticResource PicCell}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public class LVData
{
public string Desc { get; set; }
public int Progress { get; set; }
public string ProgressText { get; set; }
public string Pic { get; set; }
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LVData row = new LVData();
row.Desc = "Hello";
row.Progress = 50;
row.ProgressText = "50%";
row.Pic = "http://www.google.com/intl/en_ALL/images/logo.gif";
listView1.Items.Add(row);
}
}