1

これは単純なはずですが、見つかりません。Master-Detail Binding によって関連付けられた 2 つの Combobox があります。

<ComboBox Style="{StaticResource FixedSelectionCombo}"
          ItemsSource="{Binding ElementName=ControlRoot, Path=Clubs}"
          DisplayMemberPath="Name"
          SelectedItem="{Binding ElementName=ControlRoot,Path=SelectedClub}">
</ComboBox>
<ComboBox Style="{StaticResource FixedSelectionCombo}" 
          ItemsSource="{Binding ElementName=ControlRoot, Path=SelectedClub.PlayerLists}"
          DisplayMemberPath="Name"
          SelectedItem="{Binding ElementName=ControlRoot, Path=SelectedPlayerList}">
</ComboBox>

最初のコンボボックスで項目を選択すると、2 番目のコンボボックスに適切な PlayerList が取り込まれますが、最初の項目が自動的に選択されるようにしたいと考えています。

これはコード ビハインドで簡単に実行できますが、ResourceDictionary に配置できる Style を使用してこれを実現したいと考えています。私は試した:

  <Style x:Key="FixedSelectionCombo" TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
        <Setter Property="SelectedIndex" Value="0"/>
    </Style>

しかし、これは最初のコンボボックスで新しい選択を行った後ではなく、初めて機能します。

どうすればそれができますか?

4

2 に答える 2

3

You can solve this by using Interaction.Triggers:

<ComboBox Style="{StaticResource FixedSelectionCombo}"
          ItemsSource="{Binding ElementName=ControlRoot, Path=Clubs}"
          DisplayMemberPath="Name"
          SelectedItem="{Binding ElementName=ControlRoot,Path=SelectedClub}"
          Name="cbClubs">
</ComboBox>
<ComboBox Style="{StaticResource FixedSelectionCombo}" 
          ItemsSource="{Binding ElementName=ControlRoot, Path=SelectedClub.PlayerLists}"
          DisplayMemberPath="Name"
          SelectedItem="{Binding ElementName=ControlRoot, Path=SelectedPlayerList}">
     <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged" SourceName="cbClubs">
                <ei:ChangePropertyAction PropertyName="SelectedIndex" Value="1"/>
            </i:EventTrigger>
     </i:Interaction.Triggers>
</ComboBox>

Required namespaces:

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
于 2013-05-25T14:49:39.987 に答える