Question

I am Silverlight5 beginner and i have an error which is as below (which are for same line which i pointed in xaml code , where as i have properly referenced assembmy xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"):

Error Nested properties are not supported: DataGridTemplateColumn.CellTemplate. 
Error The attachable property 'CellTemplate' was not found in type 'DataGridTemplateColumn'.  
Error Unexpected PROPERTYELEMENT in parse rule PropertyElement ::= . PROPERTYELEMENT Content? ENDTAG..  

And cod to do so is as below:

    <data:DataGrid Grid.Row="1" x:Name="gridVersions" ItemsSource="{Binding ProgramVersion }" IsReadOnly="True" AutoGenerateColumns="False">
        <data:DataGrid.Columns>
            <data:DataGridTextColumn Header="Version" Binding="{Binding Version}" Width="2*"></data:DataGridTextColumn>
            <data:DataGridTextColumn Header="Live" Binding="{Binding Live}" Width="2*"></data:DataGridTextColumn>
            <data:DataGridTextColumn Header="Date modif." Binding="{Binding ModifDate}" Width="3*"></data:DataGridTextColumn>
            <data:DataGridTextColumn Header="..." Binding="{Binding Path=More}" Width="*"></data:DataGridTextColumn>
            **<data:DataGridTemplateColumn.CellTemplate>** //Error prone line
                <DataTemplate>
                    <Button>More Info
                        <ToolTipService.ToolTip>
                            <Border Background="White">
                                <Grid Width="Auto">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="20"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>

                                    <TextBlock  Grid.Row="0"  Grid.Column="0" Text="Name" />
                                    <TextBlock  Grid.Row="0" Grid.Column="1" Text="{Binding Name}"/>



                                    <TextBlock  Grid.Row="1"  Grid.Column="0" Text="Author" />
                                    <TextBlock  Grid.Row="1" Grid.Column="1" Text="{Binding Author}"/>

                                    <TextBlock  Grid.Row="2" Grid.Column="0" Text="Date of Creation" />
                                    <TextBlock  Grid.Row="2" Grid.Column="1" Text="{Binding DateCreation}"/>

                                    <TextBlock  Grid.Row="3" Grid.Column="0" Text="Company" />
                                    <TextBlock  Grid.Row="3" Grid.Column="1" Text="{Binding Company}"/>

                                    <TextBlock Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="1" Text="Description"/>
                                    <TextBox Grid.Row="5" Grid.Column="0" VerticalAlignment="Stretch"   VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" Grid.ColumnSpan="2" Text="{Binding Description}"/>

                                    <TextBlock  Grid.Row="6" Grid.Column="0" Text="DocUrl" />
                                    <TextBlock  Grid.Row="6" Grid.Column="1" Text="{Binding DocUrl}"/>

                                    <TextBlock  Grid.Row="7" Grid.Column="0" Text="ProgramId" />
                                    <TextBlock  Grid.Row="7" Grid.Column="1" Text="{Binding ProgramId}"/>

                                </Grid>
                            </Border>
                        </ToolTipService.ToolTip>
                    </Button>
                </DataTemplate>
            </data:DataGridTemplateColumn.CellTemplate>
        </data:DataGrid.Columns>
    </data:DataGrid>
</Grid>
Was it helpful?

Solution

You need to define an actual DataGridTemplateColumn element first:

<data:DataGrid.Columns>
    <!-- Columns ... -->
    <data:DataGridTemplateColumn>
        <data:DataGridTemplateColumn.CellTemplate>

        </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>
</data:DataGrid.Columns>

Note that in XAML syntax, when you have an element and sub-element like this:

<a> 
    <a.b>
        content
    </a.b>
</a>

Then this means to set the property b of a to "content". If the elements are of this form:

<a> 
    <b.c>
    </b.c>
</a>

That can be legal also, but it means to set the attached dependency property c of the class b on the object a. That's why you're seeing the error message:

The attachable property 'CellTemplate' was not found in type 'DataGridTemplateColumn'

The XAML parser thinks you're trying to attach a property DataGridTemplateColumn.CellTemplate ("b.c") to the element DataGrid.Columns ("a").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top