Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
Custom DataTemplates
posted

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>

Parents Reply Children
No Data