0

次のコードを使用して、データ テンプレート アイテムを作成しました。

 FrameworkElementFactory textCtrl = new FrameworkElementFactory(typeof(TextBox));            
        Binding binding1 = new Binding();
        string path = "Syncfusion";
        binding1.Path = new PropertyPath(path);
        textCtrl.SetValue(TextBox.TextProperty,binding1);
        Binding binding2 = new Binding();
        string path2 = "Text1";
        binding2.Path = new PropertyPath(path2);
        textCtrl.SetValue(TextBox.NameProperty, binding2);
        DataTemplate dt = new DataTemplate();
        dt.VisualTree = textCtrl;

データ テンプレートからテキスト ボックスを取得する方法..?

次のリンクを試しました リンク 1

リンク 2

しかし、私は物事を正しく理解していませんでした...

xamlで以下のコードを使用しました

<DataTemplate>
      <TextBlock Text="{Binding CellBoundValue}" gridcommon:VisualContainer.WantsMouseInput="False"/>
 </DataTemplate>

誰でもこれについて私を助けることができますか?

4

1 に答える 1

2

私の知る限り、Microsoft は FrameworkElementFactory の使用を推奨していません。

ただし、とにかくそれを行う場合は、DataTemplate を適用して、DataTemplate で宣言されたコントロールのインスタンスを作成する必要があります。たとえば、ContentControl または ItemsControl を使用してこれを行うことができます。

于 2013-01-30T16:46:25.600 に答える