Вот мой пример, как и обещал. При этом используется DataGrid.RowDetailsTemplate, чтобы позволить вам развернуть / свернуть список данных. Извиняюсь, что это C #, а не VB.NET.
Xaml:
<Page.DataContext>
<Samples:DataGridRowDetails2ViewModel/>
</Page.DataContext>
<Grid>
<DataGrid x:Name="dataGrid" ItemsSource="{Binding Items}"
AutoGenerateColumns="False" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" />
<DataGridTemplateColumn Header="Show details">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ToggleButton Content="Show details"
IsChecked="{Binding IsChecked}"
Checked="ToggleButtonChecked" Unchecked="ToggleButtonChecked"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate DataType="{x:Type Samples:DataItemWithDetails}">
<ItemsControl ItemsSource="{Binding Doubles}" />
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
C #
public partial class DataGridRowDetails2
{
public DataGridRowDetails2()
{
InitializeComponent();
}
private void ToggleButtonChecked(object sender, RoutedEventArgs e)
{
var button = (ToggleButton)sender;
DataGridRow dataGridRow =
(DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(button.DataContext);
dataGridRow.DetailsVisibility =
(button.IsChecked??false) ? Visibility.Visible : Visibility.Collapsed;
}
}
Конечно, вы бы использовали ObservableCollection <> и реализовали INotifyPropertyChanged для реального кода.
public class DataGridRowDetails2ViewModel
{
public DataGridRowDetails2ViewModel()
{
Items = new List<DataItemWithDetails>
{
new DataItemWithDetails{ Name = "Item 1"},
new DataItemWithDetails{ Name = "Item 2"},
new DataItemWithDetails{ Name = "Item 3"},
new DataItemWithDetails{ Name = "Item 4"},
};
}
public IList<DataItemWithDetails> Items { get; set; }
public bool IsChecked { get; set; }
}
public class DataItemWithDetails
{
public DataItemWithDetails()
{
Doubles = new List<double> {1, 2, 3, 4};
}
public string Name { get; set; }
public IList<double> Doubles { get; set; }
}