首页 文章

显示组合框选择项中的数据网格详细信息

提问于
浏览
1

我的申请表中有 comboboxdatagrid . datagrid的itemsSource来自其collectionViewSource,并且组合框中有三个 ComboBoxItem 作为警告/错误/异常,如下图所示 .
enter image description here

如何在选择相应的 ComboxBoxitem 时在数据网格上显示selecteditem行详细信息 .

这就是我的尝试 . Combobox - XAML

<ComboBox 
SelectedValuePath="{Binding ElementName=dataGrid1,Path=SelectedItem.Type,Mode=OneWay}"
Grid.Column="1" Height="32" HorizontalAlignment="Left" Name="comboBox1" >
<ComboBoxItem Content="Warning"/>
<ComboBoxItem Content="Error"/>
<ComboBoxItem Content="Exception"/>
</ComboBox>

datagrid的XAML

<DataGrid AutoGenerateColumns="False" 
IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" Name="dataGrid1">

有可能通过XAML跳过代码实现这一点吗?如果不是其他建议也是最受欢迎的 .

2 回答

  • 0

    这是一个可以帮助您的代码示例 . 它显示了一个Collection View Source,带有一个过滤器......

    XAML

    <Window x:Class="Ejemplos_EnlaceADatos.Figura5_12"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cmod="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:cine="clr-namespace:Ejemplos_EnlaceADatos.Cine"
        Title="Lista de Films" Height="200" Width="300"
    >
      <Window.Resources>
        <CollectionViewSource x:Key="films" Source="{x:Static cine:Filmes.Films}" Filter="Filter_Film">
          <CollectionViewSource.SortDescriptions>
            <cmod:SortDescription PropertyName="Título"/>
          </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
      </Window.Resources>
      <ScrollViewer>
        <StackPanel TextBlock.FontFamily="Segoe UI" Margin="6">
          <TextBlock FontSize="16" FontWeight="Bold" Foreground="Navy">
            Films:
          </TextBlock>
          <ItemsControl ItemsSource="{Binding Source={StaticResource films}}"/>
        </StackPanel>
      </ScrollViewer>
    </Window>
    

    Code Behind

    using System.Windows;
    using System.Windows.Data;
    using Ejemplos_EnlaceADatos.Cine;
    
    namespace Ejemplos_EnlaceADatos {
      public partial class Figura5_12 : Window {
    
        public Figura5_12() {
          InitializeComponent();
        }
        void Filter_Film(object sender, FilterEventArgs e) {
          e.Accepted = (e.Item is Film) && (((Film)e.Item).Género == Género.Mafia);
        }
      }
    }
    

    并过滤如下:

    Before

    enter image description here

    After

    enter image description here

    它只是一个过滤的例子,但它是一个常规的项目控制 .

  • 2

    你可以使用DataGrid的Filter,
    有关详细信息,请参阅此处:http://msdn.microsoft.com/en-us/library/ff407126.aspx

相关问题