|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionUsing a
The Range Column allows to restrict the column width as well as to fill the remaining visible area with the column. As known from HTML tables or the
The implementation supports both controlling through XAML or Code Behind. Usage of XAML styles allows a The class In the article User Settings Applied, I describe how you can persist order and size of the ListView/GridView Layout in XAMLFixed ColumnThe following example shows controlling columns with fixed widths using XAML: <ListView
Name="MyListView"
ctrl:ListViewLayoutManager.Enabled="true">
<ListView.View>
<GridView>
<GridViewColumn
DisplayMemberBinding="{Binding Path=Name}"
ctrl:FixedColumn.Width="100"
Header="Name" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=City}"
ctrl:FixedColumn.Width="300"
Header="City" />
</GridView>
</ListView.View>
</ListView>
Setting the property Proportional ColumnThe following example shows controlling columns with proportional widths using XAML: <ListView
Name="MyListView"
ctrl:ListViewLayoutManager.Enabled="true">
<ListView.View>
<GridView>
<GridViewColumn
DisplayMemberBinding="{Binding Path=Name}"
ctrl:ProportionalColumn.Width="1"
Header="Name" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=City}"
ctrl:ProportionalColumn.Width="3"
Header="City" />
</GridView>
</ListView.View>
</ListView>
Matching the Range ColumnThe following example shows controlling ranged columns with minimal/maximal widths using XAML: <ListView
Name="MyListView"
ctrl:ListViewLayoutManager.Enabled="true">
<ListView.View>
<GridView>
<GridViewColumn
DisplayMemberBinding="{Binding Path=Name}"
ctrl:RangeColumn.MinWidth="100"
Width="150"
Header="Name" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=City}"
ctrl:RangeColumn.MaxWidth="200"
Width="150"
Header="City" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=Country}"
Width="100"
ctrl:RangeColumn.MinWidth="50"
ctrl:RangeColumn.MaxWidth="150"
Header="Country" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=State}"
Width="100"
ctrl:RangeColumn.MinWidth="100"
ctrl:RangeColumn.IsFillColumn="true"
Header="Country" />
</GridView>
</ListView.View>
</ListView>
The first range column which has the value Dragging the mouse out of the configured range when resizing, the mouse cursor changes its representation to indicate this. Combined UsageIn real life, it is common to combine these column types. Their order can be varied as required: <ListView
Name="MyListView"
ctrl:ListViewLayoutManager.Enabled="true">
<ListView.View>
<GridView>
<GridViewColumn
DisplayMemberBinding="{Binding Path=State}"
ctrl:FixedColumn.Width="25"
Header="Name" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=Name}"
Width="150"
ctrl:RangeColumn.MinWidth="100"
ctrl:RangeColumn.MaxWidth="200"
Header="City" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=City}"
ctrl:ProportionalColumn.Width="1"
Header="Zip" />
<GridViewColumn
DisplayMemberBinding="{Binding Path=Country}"
ctrl:ProportionalColumn.Width="2"
Header="Country" />
</GridView>
</ListView.View>
</ListView>
ListView/GridView Layout using Code BehindIt is also possible to setup the column layout in the source code: ListView listView = new ListView();
new ListViewLayoutManager( listView ); // attach the layout manager
GridView gridView = new GridView();
gridView.Columns.Add( FixedColumn.ApplyWidth( new MyGridViewColumn( "State" ), 25 ) );
gridView.Columns.Add( RangeColumn.ApplyWidth( new MyGridViewColumn( "Name" ), 100,
150, 200 ) ); // 100...200
gridView.Columns.Add( ProportionalColumn.ApplyWidth( new MyGridViewColumn( "City" ),
1 ) ); // 33%
gridView.Columns.Add( ProportionalColumn.ApplyWidth( new MyGridViewColumn(
"Country" ), 2 ) ); // 66%
listView.View = gridView;
Columns with Custom RepresentationThe class // ------------------------------------------------------------------------
public class Customer
{
// ----------------------------------------------------------------------
public Customer()
{
} // Customer
// ----------------------------------------------------------------------
public string FirstName
{
get { return this.firstName; }
set { this.firstName = value; }
} // FirstName
// ----------------------------------------------------------------------
public string LastName
{
get { return this.lastName; }
set { this.lastName = value; }
} // LastName
// ----------------------------------------------------------------------
// members
private string firstName;
private string lastName;
} // class Customer
// ------------------------------------------------------------------------
public class CustomerFullNameColumn : ConverterGridViewColumn
{
// ----------------------------------------------------------------------
public CustomerGridViewColumn() :
base( typeof( Customer ) )
{
} // CustomerGridViewColumn
// ----------------------------------------------------------------------
protected override object ConvertValue( object value )
{
Customer customer = value as Customer;
return string.Concat( customer.FirstName, " ", customer.LastName );
} // ConvertValue
} // class CustomerFullNameColumn
Columns Represented as ImagesThe class // ------------------------------------------------------------------------
public class Customer
{
// ----------------------------------------------------------------------
public Customer()
{
} // Customer
// ----------------------------------------------------------------------
public bool IsActive
{
get { return this.isActive; }
set { this.isActive = value; }
} // IsActive
// ----------------------------------------------------------------------
// members
private bool isActive;
} // class Customer
// ------------------------------------------------------------------------
public class CustomerActiveColumn : ImageGridViewColumn
{
// ----------------------------------------------------------------------
public CustomerActiveColumn()
{
} // CustomerActiveColumn
// ----------------------------------------------------------------------
protected override ImageSource GetImageSource( object value )
{
Customer customer = value as Customer;
if ( customer != null )
{
return new BitmapImage( new Uri( customer.IsActive ? "Active.png" :
"Inactive.png" ) );
}
return null;
} // GetImageSource
} // class CustomerActiveColumn
Points of InterestAt the core of layouting the
To properly receive the required information, it is necessary to analyze the Visual Tree of the The event Tracking the property To support integration in existing systems, the required column data is kept in Attached Properties. Using the method The class The class // ----------------------------------------------------------------------
protected ImageGridViewColumn( Stretch imageStretch )
{
FrameworkElementFactory imageElement = new FrameworkElementFactory( typeof( Image ) );
// image stretching
Binding imageStretchBinding = new Binding();
imageStretchBinding.Source = imageStretch;
imageElement.SetBinding( Image.StretchProperty, imageStretchBinding );
DataTemplate template = new DataTemplate();
template.VisualTree = imageElement;
CellTemplate = template;
} // ImageGridViewColumn
History
| ||||||||||||||||||||