Filtering with XPath removes the selected value in the ComboBox that binds

I have the following setup:

This is the main screen:

    <ListView Name="lineData" Grid.Row="2" ItemsSource="{Binding ElementName=This, Path=LineInformation, ValidatesOnDataErrors=True}" 
              ItemContainerStyle="{StaticResource ItemStyle}" PreviewMouseUp="lineData_PreviewMouseUp" SelectedIndex="0" 
              Foreground="{StaticResource {x:Static SystemColors.ControlTextBrushKey}}">
        <ListView.View>
            <GridView  x:Name="gridViewItems" AllowsColumnReorder="false">
                <GridViewColumn Header="Product" Width="Auto">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <ComboBox Name="descriptionComboBox" Loaded="description_Loaded"
                                    DisplayMemberPath="Description" SelectedItem="{Binding Path=Product}" SourceUpdated="descriptionComboBox_SourceUpdated"
                                    MinWidth="200" Width="Auto" SelectionChanged="description_SelectionChanged" TargetUpdated="descriptionComboBox_TargetUpdated">
                                  <ComboBox.ItemsSource>
                                    <Binding Source="{StaticResource XmlFile}" />
                                  </ComboBox.ItemsSource>
                                </ComboBox>
                            </StackPanel>
                        </DataTemplate>                            
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

There is a button on this screen that brings up a new window as follows:

        Window newWindow = new Window();
        buildWindow.Owner = this; //MainWindow is the owner
        buildWindow.ShowDialog();

This new window filters out the values ​​that are in the combo box in the first window, for example:

        XmlDataProvider provider = Owner.FindResource("XmlFile") as XmlDataProvider;
        provider.XPath = _configuration.CreateFilterQuery();
        provider.Refresh();

Thus, combobox has a binding to this XmlFile. The problem is that now I need to keep the value displayed in comboboxes if they are in the category of the new filter.

But when I call the .Refresh () function, the selected index with the list is reset.

Any ideas on how to save the displayed text after applying the XPath query?

Thanks Hi.

+3
source share
2 answers

, , ?

0

, XmlDataProvider. , - ?

        XmlDataProvider provider = Owner.FindResource("XmlFile") as XmlDataProvider;
        XDocument cloneDoc = new XDocument(provider.Document);

        XmlDataProvider childProvider = new XmlDataProvider();
        childProvider.Document = cloneDoc;
        childProvider.XPath = _configuration.CreateFilterQuery();
        childProvider.Refresh();

        Window newWindow = new Window();
        newWindow.Provider = childProvider;
        newWindow.Owner = this; //MainWindow is the owner
        newWindow.ShowDialog();

Provider. XDocument .

0

All Articles