'DataTemplate'类型没有公共TypeConverter类

时间:2014-04-16 18:18:45

标签: wpf xaml resourcedictionary

我为DataTemplate创建了以下GridViewColumn

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!--'DataTemplate' type does not have a public TypeConverter class.-->
    <DataTemplate x:Key="myCellTemplate">        
        <TextBlock Text="{Binding}" ToolTip="{Binding}" Background="Red" />
      </DataTemplate>

</ResourceDictionary>

我在这里使用DataTemplate

    <ListView 
      ItemsSource="{Binding AllOrders}">
        <ListView.View>
            <GridView>
                <GridViewColumn 
                    DisplayMemberBinding="{Binding Id}"
                    CellTemplate="myCellTemplate" />
            </GridView>
        </ListView.View>
    </ListView>

我收到以下错误:

  

'DataTemplate'类型没有公共TypeConverter类。

我该如何解决?

1 个答案:

答案 0 :(得分:1)

myCellTemplate替换为{StaticResource myCellTemplate},如下所示:

 <GridViewColumn 
      DisplayMemberBinding="{Binding Id}"
      CellTemplate="{StaticResource myCellTemplate}" />