【发布时间】:2015-03-13 17:34:14
【问题描述】:
找不到类型“类型”。 [行:7 位置:21]
我正在尝试动态生成数据模板。它工作正常,但如果我包含此属性,我会得到上述异常。
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”吗?
-
@JamesHarcourt 问题与此无关。错误消息明确指出 XAML 解析器找不到类型
Type(实际上是x:Type,或System.Windows.Markup.TypeExtension)。 -
据我了解,就读者所知,在解析此 XAML 时基本上没有可视化树。
-
我不太确定@HighCore - OP 明确指出,只有当他尝试将 TextBox 的 width 属性绑定到第一个 telerik:GridViewCell 的 ActualWidth 属性时,才会发生错误找到了视觉树。
-
@JamesHarcourt 看到我的回答。
标签: xaml silverlight xamlreader