关于动态填充DataGrid RowDetails 绑定数据的问题
由于项目需要,要在点击DataGrid Row的时候弹出一个TabControl显示此Row 更加详细的信息。
具体效果如下图:
点击前:
点击后:
Xaml代码:
<sdk:DataGrid Name="Dg_SearchResults" RowDetailsVisibilityMode="Collapsed" AutoGenerateColumns="False" ItemsSource="{Binding}" IsReadOnly="True" > <sdk:DataGrid.RowDetailsTemplate> <DataTemplate> <StackPanel Background="LightBlue" Orientation="Vertical"> <sdk:TabControl HorizontalAlignment="Stretch" Name="tabControl1" VerticalAlignment="Stretch" DataContext="{Binding }" > <sdk:TabItem Header="基础信息" Name="Ti_BasicAttribute"> <Grid> <Image Height="119" HorizontalAlignment="Left" Margin="5,20,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="110" Source="./../../Images/Printer.jpg" /> </Grid> </sdk:TabItem> <sdk:TabItem Header="详细信息" Name="Ti_SpecialityAttribute"> <ScrollViewer Height="170"> <Grid> <TextBlock Height="23" HorizontalAlignment="Left" Margin="275,70,0,0" Name="Tb3" Text="采购组织形式:" VerticalAlignment="Top" /> </Grid> </ScrollViewer> </sdk:TabItem> </sdk:TabControl> </StackPanel> </DataTemplate> </sdk:DataGrid.RowDetailsTemplate> <sdk:DataGrid.Columns> <sdk:DataGridTemplateColumn > <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ToggleButton x:Name="btnSelect" Template="{StaticResource ToggleButtonTemplate}" Click="btnSelect_Click" /> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> <sdk:DataGridTextColumn Binding="{Binding Path=No}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="No" Width="Auto" /> <sdk:DataGridTextColumn Binding="{Binding Path=UnitAreaID}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="地区" Width="Auto" /> </sdk:DataGrid.Columns> </sdk:DataGrid>
public class AssetData { AssetType assetType = AssetType.SpecialEquip; public AssetType AssetType { get { return assetType; } set { assetType = value; } } AssetCardDetail assetCardDetail = new AssetCardDetail(); public AssetCardDetail AssetCardDetail { get { return assetCardDetail; } set { assetCardDetail = value; } } List<AssetImage> imageList = new List<AssetImage>(); public List<AssetImage> ImageList { get { return imageList; } set { imageList = value; } } List<AssetAttachment> attachmentList = new List<AssetAttachment>(); public List<AssetAttachment> AttachmentList { get { return attachmentList; } set { attachmentList = value; } } List<AssetExtendEquip> extendEquipList = new List<AssetExtendEquip>(); public List<AssetExtendEquip> ExtendEquipList { get { return extendEquipList; } set { extendEquipList = value; } } List<AssetSpecialEnvInfo> speicalEnvInfoList = new List<AssetSpecialEnvInfo>(); public List<AssetSpecialEnvInfo> SpeicalEnvInfoList { get { return speicalEnvInfoList; } set { speicalEnvInfoList = value; } } AssetTypeDetail assetTypeDetail = new AssetTypeDetail(); public AssetTypeDetail AssetTypeDetail { get { return assetTypeDetail; } set { assetTypeDetail = value; } } }