2011-07-27 15 views
1

私は複雑なフォームアプリケーションを開発しています。各行には最後にプラスボタンがあり、そのすぐ下に新しい行を追加してください。私が実装しているものの例が必要な場合は、iTunesとスマートプレイリストの編集ダイアログをチェックしてください。これは、私が使い慣れたクエリービルダーを構築するために使用しているクエリーとネストを使用しています。どのように私は(いくつかのスペース上のタブ)お互いの下に行を入れ子にし、お互いの間にグリッドに行を追加するためのヒント?Silvelight:グリッドの行間にコントロールを動的に追加する方法は?

答えて

0

あなたは、オブジェクトがのObservableCollectionに入れ、その後、データはツリービューの項目ソースにバインドするとあなたは、各行を表すことができTreeView control

を使用して試みることができます。各行オブジェクトには、そのネストされた行オブジェクトのObservableCollectionを含むChildrenプロパティもあります。

class Row 
{ 
    public ObservableCollection<Row> Children { get; set; } 

    // .... 
} 

partial class MainPage 
{ 
    public ObservableCollection<Row> Rows{ get; set; } 

    public MainPage() 
    { 
     //Add your initial rows 
     this.AddRow(new Row(...)); 
     this.AddRow(new Row(...)); 
     //... 

     this.InitializeComponents(); 
    } 

    public void AddRow(Row newRow, Row parentRow=null) 
    { 
     if(parentRow == null) 
     { 
      // Add new row to root of tree 
      this.Rows.Add(newRow); 
     } 
     else 
     { 
      //Add new row as child of an existing row of tree 
      parentRow.Children.Add(newRow); 
     } 
    } 
} 

<UserControl x:Class="MainPage" x:Name="mainPageUserControl"> 
    <TreeView ItemsSource="{Binding Rows, ElementName=mainPageUserControl}"> 
     <HierarchicalDataTemplate ItemsSource="{Binding Children}"> 
      <!-- Template the behaviour/look of your rows as needed --> 
     </HierarchicalDataTemplate> 
    </TreeView> 
</UserControl> 

新しい行を追加または削除するには、あなたは、単に監視可能なコレクションからRowオブジェクトを追加/削除することができます。 ObservableCollectionにバインドすると、行が追加/削除された場合にTreeViewが自動的に更新されます。

+0

これを今試してみます。ありがとう! – sean

関連する問題