2012-04-26 69 views
3

我有以下设置:筛选使用XPath将删除选定的组合框被结合价值

这是主屏幕:

<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

我认为你的子窗口将不得不拥有它自己的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(); 

您必须子类化窗口并添加该提供程序属性。您也可以创建一个XDocument属性,并将所有内容绑定到子窗口中。