Reputation: 2273
The type 'Type' was not found. [Line: 7 Position: 21]
I'm trying to dynamically generate a datatemplate. it works fine, but if I include this attribute, I get the above exception.
Width="{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:GridViewCell}}}"
And the complete method:
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);
}
Upvotes: 0
Views: 460
Reputation: 6154
You have a Silverlight
project. Silverlight does not support the markup extension x:Type
. Ancestor bindings in Silverlight look like this:
{Binding Path=Foo, RelativeSource={RelativeSource AncestorType=UserControl}}
[Edit]
And btw you can't bind to ActualWidth
. You have to observe the SizeChanged
event and have some handling code. You will find quite elegant solutions to this problem here: binding-to-actualwidth.
Upvotes: 1
Reputation: 44048
The error is caused because the XAML parser can't resolve the type x:Type
in XAML to a valid CLR type, probably because namespace mappings in XAML cannot be properly processed by the XAML reader without proper context.
I have a customized version of this which uses a ParserContext
to define the XML namespace mappings for XAML:
var context = new ParserContext {XamlTypeMapper = new XamlTypeMapper(new string[0])};
context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
//... And so on add other xmlns mappings here.
var template = (DataTemplate) XamlReader.Parse(yourXAMLstring, context);
Upvotes: 1