0

这是我的问题

我有一个 DataGrid,这是他的来源

var Query = from a in m.Table1
                       join p in m.Table2
                       on a.Value1 equals p.Value1
                       join c in m.Table3 on a.Value2 equals  c.Value2 
           select new {
                        value1 = a.value1
                        value2 = p.value2
                        value3 = c.value3
                        value4 = a.value4

                      };
    <DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" Margin="84,75,0,0"
 Name="Grid_Exmple" Width="478" Height="219" VerticalAlignment="Top" SelectionChanged="Grid_Exmple_SelectionChanged">
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding value1 }" Header="value1 " IsReadOnly="True" x:Name="dgrvalue1 "  />
                        <DataGridTextColumn Binding="{Binding value2 }" Header="value2 " IsReadOnly="True"  x:Name="dgrvalue2 " />
                        <DataGridTextColumn Binding="{Binding value3 }" Header="value3 " IsReadOnly="True"  x:Name="dgrvalue3" />
                        <DataGridTextColumn Binding="{Binding value4}" Header="value4" IsReadOnly="True"  x:Name="dgrvalue4" />
                    </DataGrid.Columns>

当我们按下 DataGrid 选择事件时

  private void Grid_Exmple_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    Here I try To Get The properties 

我可以看到 e.AddedItems 中的属性,但我无法投射它

    ((<>f__AnonymousType2<int,int?,decimal?,decimal?,string,string,string,int,string>)(((object[])(e.AddedItems))[0])).Value1

  }
4

1 回答 1

2

至少有两种可能:

  1. 创建一个命名类型,用它填充网格,然后转换回这个类型。
  2. 投射dynamic并做任何你想做的事。
于 2012-04-23T20:10:25.107 回答