I have a problem with ListView design in Expression Blend that is harder than I thought it should.
I'd like to just draw a screen using XAML. This WILL NOT run inside an application, is just a static design study that should be rendered for viewing in the design window of Expression Blend, exclusively.
I have this so far:
<ListView x:Name="examList" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto"/>
<GridViewColumn Header="Setup" Width="Auto"/>
<GridViewColumn Header="Protocol" Width="Auto" />
<GridViewColumn Header="Channels" Width="Auto"/>
<GridViewColumn Header="Duration" Width="Auto"/>
</GridView>
</ListView.View>
<ListViewItem>
<TextBlock Text="stuff" /> <!-- what should I put here??? -->
</ListViewItem>
</ListView>
The problem is: I don't have a clue how I should create ListViewItems with one string or number value for each field (each column in the GridView).
I would appreciate any help, with or without code-behind, but a necessary requirement for my workflow is that it renders at design time inside Expression Blend without the need to run the application, and preferrably that the data is not bound from another file, but entered by hand directly into the XAML (I don't mind it, actually I WANT it).
I found this answer, but it doesn't do what I need, I think.
Thanks for reading!
You can use a string array inside your ListViewItem
and use the DisplayMemberBinding
to specify which which index should be displayed in which column.
<ListView x:Name="examList" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto"
DisplayMemberBinding="{Binding [0]}"/>
<GridViewColumn Header="Setup" Width="Auto"
DisplayMemberBinding="{Binding [1]}"/>
<GridViewColumn Header="Protocol" Width="Auto"
DisplayMemberBinding="{Binding [2]}"/>
<GridViewColumn Header="Channels" Width="Auto"
DisplayMemberBinding="{Binding [3]}" />
<GridViewColumn Header="Duration" Width="Auto"
DisplayMemberBinding="{Binding [4]}"/>
</GridView>
</ListView.View>
<ListViewItem>
<x:Array Type="{x:Type sys:String}">
<sys:String>This is Date</sys:String>
<sys:String>This is Setup</sys:String>
<sys:String>This is Protocol</sys:String>
<sys:String>This is Channels</sys:String>
<sys:String>This is Duration</sys:String>
</x:Array>
</ListViewItem>
</ListView>
Where sys:
is xmlns:sys="clr-namespace:System;assembly=mscorlib"
Or you can create your own datatype which will hold the values:
public class Exam
{
public string Date { get; set; }
public string Setup { get; set; }
//...
}
And use it in the ListViewItem
:
<ListView x:Name="examList" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto"
DisplayMemberBinding="{Binding Date}"/>
<GridViewColumn Header="Setup" Width="Auto"
DisplayMemberBinding="{Binding Setup}"/>
</GridView>
</ListView.View>
<ListViewItem>
<local:Exam Date="2001/1/1" Setup="Some setup" />
</ListViewItem>
</ListView>
Where local:
point to your Exam
class namespace.