Hi
I am having great trouble populating the grid using TemplateColumn. Basically, nothing works as expected:
- TextBox objects do not take up all the space (as seen in attachment), despite trying both HorizontalAlignment and HorizontalContentAlignment set to "Stretch" for all the respective elements of the template- CheckBox and ComboBox seem to have a different alignment when cell is in focus (as seen in attachment)- Certain cells should be empty. However, constructing an empty DataTemplate (or with an empty TextBlock) does not help. The cell then shows the name of the class (with full namespace) as its content.
I've also attempted UnboundColumn with no luck and I also suspect that is not the right path.
After 11 years of programming, I thought I'd be capable of something seemingly trivial, but obviously I was badly mistaken.
Some further info below.
Thanks
Every column is a TemplateColumn with ItemTemplate and EditorTemplate both set as below, with their respective fields
<DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Code="clr-namespace:UI.Silverlight.Code;assembly=UI.Silverlight"> <Code:TextTemplateSelector HorizontalContentAlignment="Stretch" Content="{Binding}" DataFieldName="Other" ColumnType="System.Boolean"/></DataTemplate>
TextTemplateSelector class then determines if the current row should contain text fields, and if so, renders them as below<DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Code="clr-namespace:UI.Silverlight.Code;assembly=UI.Silverlight"> <Grid HorizontalAlignment="Stretch" MinHeight="25" VerticalAlignment="Center"> <TextBox Text="{Binding PtId}"/> </Grid></DataTemplate>
If the current row requires special handling, the combobox should be the output of the first cell, rest of the cells should be blank.<DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Code="clr-namespace:UI.Silverlight.Code;assembly=UI.Silverlight"> <Grid HorizontalAlignment="Stretch" MinHeight="25" VerticalAlignment="Center"> <CheckBox IsChecked="{Binding Other}" /> </Grid></DataTemplate>
I've just created a support ticket, so our Developer Support team can research this.
Kiril
Thanks, I think I should point out a few things, some of which might or might not have something to do with this not helping me in my case:
1. I use TemplateColumn, not UnboundColumn.
2. Columns are added at runtime in code behind, so this is done like below
var cellTemplate = CreateDataTemplate(propertyInfo, false); var cellEditTemplate = CreateDataTemplate(propertyInfo, true);
var column = new TemplateColumn { Key = propertyInfo.Name, HeaderText = propertyInfo.Name, ItemTemplate = cellTemplate, EditorTemplate = cellEditTemplate, EditorHorizontalContentAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Stretch };
return column;
Oddly enough, if I change the alignment to HorizontalAlignment.Center or .Right, there is effect as expected. But it will not stretch.
Hello,
For the UnboundField, the alignment of the content and the editor inside are determined by the HorizontalContentAlignment and VerticalContentAlignment properties of the column itself. Please find the attached project with this implemented. Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4