Articles → LIGHT SWITCH 2011 → Datagrid Header Text Wrapping In Lightswitch 2011
Datagrid Header Text Wrapping In Lightswitch 2011
Software Requirement
- Visual studio 2010 is installed on your machine.
- Visual Studio 2010 service pack 1 is installed on your machine.
- Microsoft Visual Studio Light switch 2011 is installed on your machine.
Prerequisite Knowledge
- How to create lightswitch project?
- How to create an entity in lightswitch?
- How to create a screen in lightswitch?
- What is the ControlAvailable event in lightswitch?
- Basics about Silverlight.
- How to create DataTemplate in Silverlight?
Steps For Execution
- Create a new lightswitch project
- Create a new table
- Add new screen
- Add data in the table
- Add ControlAvailable event for the grid
- Add code for column wrap
Create A New Lightswitch Project
Click to Enlarge
Create A New Table
Click to Enlarge
Add New Screen
Click to Enlarge
Add Data In The Table
Click to Enlarge
Add Controlavailable Event For The Grid
partial void EditableEmployeesGrid_Created() {
this.FindControl("grid").ControlAvailable += new EventHandler < ControlAvailableEventArgs > (EditableEmployeesGrid_ControlAvailable);
}
void EditableEmployeesGrid_ControlAvailable(object sender, ControlAvailableEventArgs e) {
}
Add Code For Column Wrap
partial void EditableEmployeesGrid_Created() {
this.FindControl("grid").ControlAvailable += new EventHandler <ControlAvailableEventArgs> (EditableEmployeesGrid_ControlAvailable);
}
DataGrid _grid;
void EditableEmployeesGrid_ControlAvailable(object sender, ControlAvailableEventArgs e) {
if (e.Control is DataGrid) {
_grid = (DataGrid) e.Control;
StringBuilder sb = new StringBuilder();
sb.Append(@ "<DataTemplate
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>");
sb.Append(@ "<TextBlock TextWrapping='Wrap' Text='{Binding}'/>");
sb.Append(@ "</DataTemplate>");
Style newGridHeaderStyle = new Style(typeof (DataGridColumnHeader));
newGridHeaderStyle.Setters.Add(new Setter {
Property = DataGridColumnHeader.ContentTemplateProperty, Value = (DataTemplate) XamlReader.Load(sb.ToString())
});
_grid.ColumnHeaderStyle = newGridHeaderStyle;
}
}
Output
Click to Enlarge