わかりました...私は子供のItemsControlデータテンプレートの内部から親へのItemsControlのプロパティをバインドできるようにする必要があります。は、WPFは、子のItemsControlデータテンプレートの内部から親のItemsControlにバインド
<ItemsControl ItemsSource="{Binding Path=MyParentCollection, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Path=MySubCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=MyParentCollection.Value, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
のはMyParentCollection(アウターコレクション)は、次の型であると仮定しよう:
public class MyObject
{
public String Value { get; set; }
public List<MyChildObject> MySubCollection { get; set;
}
とのは、上記のクラスからMyChildObjectは、次の型であると仮定しましょう:
public class MyChildObject
{
public String Name { get; set; }
}
はどのようにして、内部データテンプレートの内部からMyParentCollection.Valueに特異的に結合することができますか?私は実際にFindAncestorをタイプごとに使用することはできません。なぜなら、両方のレベルとも同じタイプを使用しているからです。私は、外側のコレクションに名前をつけ、内側のバインディングにElementNameタグを使用しても、それでもプロパティを解決できないと考えました。
どのような考えですか?私はItemsControlには
<DataTemplate>
<ItemsControl ItemsSource="{Binding Path=MySubCollection}" Tag="{Binding .}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Tag.Value, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
がテストされていません動作しますが、正しい方向にあなたにヒントを与えることができる...
FindAncestorモードを使用できず、タイプレベルと祖先レベルの両方を指定できませんか? –
はうーん、でも、この後で、私は混乱していく予定です。これは有望と思われる –
を見てみましょう...先祖のレベルを考えるとしませんでしたあなたはそれが –