【发布时间】:2018-07-02 15:47:36
【问题描述】:
对于我拥有的 ListView,行中有几个组合框。我还有一个绑定到所选行的文本框,以显示 ListView 下方行中的其他信息。问题是,当您连续单击 ComboBox 时,该行的 ListView 选定项/索引不会更改。选择该行中的 ComboBox 时,如何更改该行的 ListView 中的选定项?
这是我的带有 ComboBox 的 ListView:
<ListView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" VerticalAlignment="Stretch"
ItemsSource="{Binding Equations.DataExpressions}" SelectedItem="{Binding Equations.SelectedExpression}" SelectedIndex="0">
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsValidExpression}" Value="false">
<Setter Property="Background" Value="#FF8080" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Path" Width="90">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.PathItems}"
SelectedValue="{Binding EvaluatedPath}" Margin="-6, 0, -6, 0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
【问题讨论】: