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);
}
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.