Hello to all! I have the following problem: there is such a code

<Window x:Class="Project.Sorts" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding RelativeSource={RelativeSource Self}}" Title="Window" Height="159.022" Width="527.82" ResizeMode="NoResize"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <ListView x:Name="lView" ItemsSource="{Binding ItemsLW}" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="3"> <ListView.View> <GridView x:Name="grView"> <GridViewColumn Header="Col1" Width="Auto" x:Name="col1"> <GridViewColumn.CellTemplate> <DataTemplate > <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding TextForTb}" Margin="5,0,5,0"></TextBlock> <ComboBox Width="Auto" MinWidth="80" ItemsSource="{Binding Cols}" SelectedIndex="0" > </ComboBox> </StackPanel> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Col2" Width="Auto" x:Name="col2"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox Name="cbVars" Width="Auto" MinWidth="80" ItemsSource="{Binding Variants}"></ComboBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> <StackPanel Grid.Row="1" HorizontalAlignment="Stretch" FlowDirection="RightToLeft" Orientation="Horizontal"> <Button Width="50" VerticalAlignment="Center" Content="Cancel" Margin="5,0,0,0" IsCancel="True"></Button> <Button x:Name="btnOK" Width="50" VerticalAlignment="Center" Content="ОК" Margin="5" Click="btnOK_Click"></Button> </StackPanel> </Grid> 

It turns out this window: http://i.stack.imgur.com/cIzBh.png How can I get SelectedValue from each combo box in this ListView? Thanks in advance for the answers!

  • Look for a solution on this site, I have already answered the same question somewhere. - Ivan Navoznov

1 answer 1

found

  1. looking for all the find FindAllControls<ComboBox>(this, list) boxes FindAllControls<ComboBox>(this, list)

  2. and loop to stretch the SelectedValue property