Expander
一度に1つずつ開いて使用しようとしていました。MSDNフォーラムリンクからコードを入手しました。
<ListBox>
<!-- all styles and templates-->
<Expander Header="One"><!-- some content --></Expander>
<Expander Header="Two"><!-- some other content --></Expander>
</ListBox>
正常に動作しています。上記のエキスパンダーの1つだけが一度に開きます。
しかし、ネストされたエキスパンダーを試してみると、下のエキスパンダーは上記のコードのように開閉しません。以下のようにエキスパンダー「Two」にコンテンツを追加した場合の意味
<Expander Header="Two">
<ListBox>
<!-- same styles and templates as above-->
<Expander Header="Sub-One"><!-- some content --></Expander>
<Expander Header="Sub-Two"><!-- some other content --></Expander>
</ListBox>
</Expander>
エキスパンダー「Sub-One」と「Sub-Two」は、エキスパンダー「Two」が接続されているものと何らかの形でリンクされています。 ListBoxItem
バインディングに変更を加える必要があると思いますが、できませんでした。
<Style TargetType="{x:Type Expander}">
<Setter Property="IsExpanded"
Value="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
</Style>
どんなガイダンスも大いに役立ちます。
注:-私が試したいくつかのこと
-
-コードでExpanderの親を確認しましたが、ListBoxのみが表示され、階層にListBoxItemはありませんでした-AncestorLevelに
異なる値を追加しようとしましたが、1つ以外の値は機能しません-ListBox
SelectedIndexにバインドすることを考えていましたが、これも作成できませんコンバーターを使用しても、SelectedIndexをIsExpandableに変換することは考えられませんでした。