0

次のようにいくつかの ComboBoxes を設定しています。

    <ComboBox Name="CB_OS" Grid.Row="5" ItemsSource="{Binding OS_Sellection}" SelectedIndex="0" Margin="2" SelectionChanged="OSSelectionChanged">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <ComboBoxItem Content="{Binding Name}" IsSelected="{Binding IsSelected, Mode=TwoWay}"/>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

ComboBox には ComboBoxItems が正しく入力されますが、テキスト (コンテンツ) をクリックしても項目が選択されません。選択した項目を実際に変更するには、テキストがない場所をクリックする必要があります。

これを次のように変更すると:

<ComboBox Name="CB_OS" Grid.Row="5" SelectedIndex="0" Margin="2" SelectionChanged="OSSelectionChanged">
            <ComboBoxItem Content="OOOOOOOOO"/>
            <ComboBoxItem Content="OOOOOOOOO"/>
            <ComboBoxItem Content="OOOOOOOOO"/>
</ComboBox>

それは正常に動作します。

OS_Selection には、次のメンバーのみが含まれます。

private string name;
private bool isChecked;
private bool isSelected;

だから私の質問は次のとおりです: 行全体 (項目) をクリック可能にするにはどうすればよいですか?

4

1 に答える 1

1

ComboBoxItemの中に a を入れないでください。ComboBox.ItemTemplate

これを変える:

     <ComboBox Name="CB_OS" Grid.Row="5" ItemsSource="{Binding OS_Sellection}" SelectedIndex="0" Margin="2" SelectionChanged="OSSelectionChanged">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <ComboBoxItem Content="{Binding Name}" IsSelected="{Binding IsSelected, Mode=TwoWay}"/>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

このため:

<ComboBox Grid.Row="5" Margin="2"
          ItemsSource="{Binding OS_Sellection}"
          DisplayMemberPath="Name"/>

また、WPF はprivate fieldsにのみバインドしませんpublic properties

于 2013-09-18T16:52:58.423 に答える