1

エキスパンダーを備えたテンプレート化されたグループ化されたリストボックスを備えたUserControlがあり、いつでも1つのエキスパンダーのみを開きたいです。サイトを閲覧しましたが、IsExpandedをIsSelectedにバインドする以外に何も見つかりませんでした。これは、私が望んでいるものではありません。

Expandedイベントにループして、Expandedイベントで渡されたExpanderではないすべてのコードを閉じるコードをExpandedイベントに入れようとしています。どうやって彼らにたどり着くのかわからないようです。ListBox.Items.Groupsを試しましたが、それらを取得する方法がわかりませんでした。ListBox.ItemContainerGenerator.ContainerFromItem(またはIndex)を試しましたが、何も返されませんでした。

ありがとう

現在のマークアップは次のとおりです。

<ListBox Name="ListBox">
<ListBox.GroupStyle>
<GroupStyle>  
  <GroupStyle.ContainerStyle>  
    <Style TargetType="{x:Type GroupItem}">  
      <Setter Property="Template">  
        <Setter.Value>  
          <ControlTemplate TargetType="{x:Type GroupItem}">  
            <Border BorderBrush="CadetBlue" BorderThickness="1">  
              <Expander BorderThickness="0,0,0,1" Expanded="Expander_Expanded"  
                        Focusable="False"   
                        IsExpanded="{Binding IsSelected,  
                        RelativeSource={RelativeSource FindAncestor, AncestorType=
                                               {x:Type ListBoxItem}}}" >  
                <Expander.Header>  
                  <Grid>  
                    <StackPanel  Height="30" Orientation="Horizontal">  
                      <TextBlock Foreground="Navy"  FontWeight="Bold"  
                                 Text="{Binding Path=Name}" Margin="5,0,0,0"   
                                 MinWidth="200" Padding="3"   
                                 VerticalAlignment="Center" />  
                      <TextBlock Foreground="Navy" FontWeight="Bold"   
                                 Text=" Setups: " VerticalAlignment="Center" 
                                 HorizontalAlignment="Right"/>
                      <TextBlock Foreground="Navy" FontWeight="Bold" 
                                 Text="{Binding Path=ItemCount}" 
                                 VerticalAlignment="Center" 
                                 HorizontalAlignment="Right"  />  
                    </StackPanel>   
                  </Grid>  
                </Expander.Header>  
                <Expander.Content>  
                  <Grid Background="white" >
                    <ItemsPresenter />  
                  </Grid>  
                </Expander.Content>  
                <Expander.Style >  
                  <Style TargetType="{x:Type Expander}">  
                    <Style.Triggers>  
                      <Trigger Property="IsMouseOver" Value="true">  
                        <Setter Property="Background">  
                          <Setter.Value>  
                            <LinearGradientBrush StartPoint="0,0" 
                                                 EndPoint="0,1">  
                              <GradientStop Color="WhiteSmoke"
                                            Offset="0.0" /> 
                              <GradientStop Color="Orange" Offset="1.0" />
                            </LinearGradientBrush>
                          </Setter.Value>
                        </Setter>  
                      </Trigger>
                      <Trigger Property="IsMouseOver" Value="false"
                        <Setter Property="Background">
                          <Setter.Value>
... 
4

1 に答える 1

1

ListBoxItemのテンプレートでは、同じグループを共有するRadioButtonを使用して、のIsCheckedtoIsSelectedをバインドしListBoxItem、Expanderとして再テンプレート化できるため、のIsExpandedtoIsCheckedをバインドできますTemplatedParent

于 2010-09-01T15:02:01.327 に答える