未找到类型“类型”。 [行:7位置:21]Silverlight - XamlParseException未找到类型“类型”
我正试图动态生成一个数据模板。它工作正常,但如果我包含此属性,我会得到上述异常。
Width="{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:GridViewCell}}}"
以及完整的方法:
public DataTemplate GetTextColumnTemplate(int index)
{
string templateValue = @"
<DataTemplate
xmlns:sys=""clr-namespace:System;assembly=mscorlib""
xmlns:telerik=""http://schemas.telerik.com/2008/xaml/presentation""
xmlns=""http://schemas.microsoft.com/client/2007""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<StackPanel>
<TextBox Width=""{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:GridViewCell}}}"" Text=""{Binding Path=V" + (index + 1).ToString() + @",Mode=TwoWay}"" AcceptsTab=""True"" AcceptsReturn=""True""/>
</StackPanel>
</DataTemplate>";
return (DataTemplate)XamlReader.Load(templateValue);
}
您确定Visual Tree在发生错误时包含“telerik:GridViewCell”吗? – 2015-03-13 17:52:34
@JamesHarcourt问题与此无关。错误消息清楚地表明XAML解析器找不到'Type'类型(实际上是'x:Type'或'System.Windows.Markup.TypeExtension')。 – 2015-03-13 17:55:17
就我所知,基本上在解析这个XAML的时候没有可视化树,只要读者知道。 – 2015-03-13 17:57:34