2013-03-22 76 views
1

我在我的應用程序中有comboboxdatagrid。 datagrid從其collectionViewSource中有它的itemsSource,並且在組合框中有三個ComboBoxItem作爲警告/錯誤/異常,如下圖所示。 enter image description here顯示來自組合框selecteditem的數據網格細節

如何在選擇相應的ComboxBoxitem時在數據網格上顯示selecteditem行詳細信息。

這是我所嘗試過的。 組合框 - 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來實現這一跳過後面的代碼?如果不是其他建議也是最受歡迎的。

+0

有沒有機會拒絕背後的代碼?也許你在使用'CDATA'在你的XAML中編寫你的代碼,但我不知道如何使用這個,我會推薦使用像[RaulOtaño]這樣的普通代碼(http://stackoverflow.com/a/15579909/1993545 )在他的例子 – WiiMaxx 2013-03-25 10:12:26

+0

中沒有。以避免代碼後面只是一個選項..但如果有一種方法來實現代碼後面我可以使用它.. – user1221765 2013-03-25 10:13:45

+0

你是否使用任何模式,例如MVVM? – WiiMaxx 2013-03-25 10:18:47

回答

2

這是一個代碼示例,可以幫助你。它顯示了一個集合查看源文件,帶有過濾器...

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> 

代碼隱藏

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); 
    } 
    } 
} 

和過濾這樣的:

以前

enter image description here

enter image description here

它僅僅是濾波的示例,但是它與常規項的控制。

相關問題