Xaml:不支持嵌套属性:DataGridTemplateColumn.CellTemplate。

时间:2014-04-25 15:22:53

标签: c# .net silverlight xaml silverlight-5.0

我是Silverlight5初学者,我有一个错误,如下所示(对于我在xaml代码中指向的同一行,我在其中正确引用了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..  

鳕鱼这样做如下:

                                                    

    <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>

1 个答案:

答案 0 :(得分:3)

您需要先定义一个实际的DataGridTemplateColumn元素:

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

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

请注意,在XAML语法中,当您有一个像这样的元素和子元素时:

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

然后,这意味着将b的属性a设置为&#34;内容&#34;。如果元素是这种形式:

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

这也可以是合法的,但它意味着在对象c上设置类b的附加依赖项属性a。这就是您查看错误消息的原因:

  

可附加属性&#39; CellTemplate&#39;未在类型&#39; DataGridTemplateColumn&#39;

中找到

XAML解析器认为您正在尝试将属性DataGridTemplateColumn.CellTemplate(&#34; b.c&#34;)附加到元素DataGrid.Columns(&#34; a&#34 ;)