我有以下设置:
这是主屏幕:
<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>
此屏幕有一个按钮,可以调用这样一个新窗口:
Window newWindow = new Window();
buildWindow.Owner = this; //MainWindow is the owner
buildWindow.ShowDialog();
这个新窗口过滤掉第一个窗口中组合框中的值,如下所示:
XmlDataProvider provider = Owner.FindResource("XmlFile") as XmlDataProvider;
provider.XPath = _configuration.CreateFilterQuery();
provider.Refresh();
因此组合框具有与此XmlFile的绑定。我遇到的问题是,如果它们属于新过滤器的类别,我现在需要保持组合框中显示的值。
但是当我调用.Refresh()函数时,组合框的选定索引会被重置。
如何在应用XPath查询后如何维护显示的文本?
谢谢,问候。
答案 0 :(得分:0)
必须尝试在刷新之前记住选择,然后检查新过滤器后该值是否仍然存在并选择它?
答案 1 :(得分: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属性,然后绑定子窗口中的所有内容。