我正在寻找的行为是,当单击一行时,另一个数据网格显示来自同一源的字符串的子数组。相反,我得到的是包含每个字符串长度的行。
XAML
<DataGrid Name="dg">
<DataGrid.Columns>
<DataGridTextColumn Header="Code" Binding="{Binding Code}" />
...
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid Name ="dg2" ItemsSource="{Binding Emails}" RowDetailsVisibilityMode="VisibleWhenSelected" >
<DataGrid.Columns>
<DataGridTextColumn Header="Email" Binding="{Binding Email}" />
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
的ItemsSource
<Job GUID="5a790ed3-e3a3-4251-9906-36cfdcdc2fb2">
<Code>something</Code>
<Emails>
<Email>gnhfgj</Email>
<Email>gjfjgfj</Email>
</Emails>
</Job>
<Job GUID="5a790ed3-e3a3-4251-9906-36cfdcdc2fb2">
<Code>somethingelse</Code>
<Emails>
<Email>email</Email>
</Emails>
</Job>
C#
string xmlFileName = "Jobs.xml";
XmlSerializer reader = new XmlSerializer(typeof(List<Job>));
StreamReader file = new StreamReader(xmlFileName);
List<Job> load = (List<Job>)reader.Deserialize(file);
dg.ItemsSource = load;
答案 0 :(得分:0)
找到答案。这直接绑定到字符串。
<DataGridTextColumn Header="Email" Binding="{Binding}" />