Articles → LIGHT SWITCH 2011 → Datagrid header text wrapping in lightswitch 2011

Datagrid header text wrapping in lightswitch 2011


























Software requirement











Prerequisite knowledge

















Steps for execution



















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


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, December 05, 2012

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250