0

タイプ 'Type' が見つかりませんでした。[ライン: 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);

        }
4

2 に答える 2

1

このエラーは、XAML パーサーが XAML の型x:Typeを有効な CLR 型に解決できないために発生します。おそらく、適切なコンテキストがないと、XAML リーダーが XAML の名前空間マッピングを適切に処理できないためです。

を使用して XAML の XML 名前空間マッピングを定義する、これのカスタマイズされたバージョンがあります。ParserContext

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);
于 2015-03-13T17:59:38.880 に答える
1

あなたはSilverlightプロジェクトを持っています。Silverlight はマークアップ拡張機能をサポートしていませんx:Type。Silverlight の祖先バインディングは次のようになります。

{Binding Path=Foo, RelativeSource={RelativeSource AncestorType=UserControl}}

[編集]ところで、あなたはにバインドすることはできませんActualWidthSizeChangedイベントを観察し、処理コードを用意する必要があります。ここで、この問題に対する非常に洗練された解決策を見つけることができます: binding-to-actualwidth

于 2015-03-16T10:36:50.677 に答える