WPF中datagrid嵌套datagrid,数据绑定问题
大家好,我现在用DataGrid嵌套ListBox,ListBox的ItemsSource是通过转换器将字符串转换为DataView,现在出现的问题是ListBox的ItemsSource是不同的,但是ListBox里的TextBlock的text值是一样的。我想通过ListBox的ItemsSource的不同让TextBlock显示不同的数据.
<DataGrid Name="FileDataGrid" AutoGenerateColumns="False" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="2" CanUserAddRows = "false">
<DataGrid.Columns>
<DataGridTemplateColumn IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding senderName}"></TextBlock>
<TextBlock Margin="5 0 0 0" Grid.Column="1" Grid.Row="0" Text="{Binding sendTime,StringFormat='HH:mm:ss'}"/>
<ListBox Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding message,Converter={StaticResource imageSourceconverter}}" ScrollViewer.CanContentScroll="False">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding url}"></TextBlock></DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
public class DataGridModel
{
private List<ListViewModel> listViewModels = new List<ListViewModel>();
public List<ListViewModel> ListViewModels
{
get { return listViewModels; }
set { listViewModels = value; }
}
}
public class ListViewModel
{
public int Age { get; set; }
public string Name { get; set; }
}
List<DataGridModel> DataGridItemSource = new List<DataGridModel>();
dataGrid.ItemSource=DataGridItemSource;