Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
985
Xamdatagrid subrow headers
posted

Hello Team,

I am trying to set the headers for the subrows in a xamdatagrid. How can I achieve that?

Below is the source code for a sample project that has expandable rows. I have also attached the project so you can download it:

XAML

<Window xmlns:ig="http://schemas.infragistics.com/xaml" x:Class="ExapndAllMenu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:ExapndAllMenu"
xmlns:igDP="http://infragistics.com/DataPresenter">
<Grid>
<igDP:XamDataGrid
Name="xamDataGrid1"
DataSource="{Binding Data}">
<igDP:XamDataGrid.FieldLayoutSettings>
<!-- Set the ExpansionIndicatorDisplayMode so that when a record
is displayed it will be checked to see if it has any child
records. The expansions indicator will only be displayed
if the record has children. -->
<igDP:FieldLayoutSettings ExpansionIndicatorDisplayMode="CheckOnDisplay"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.Resources>
<local:ShouldDisplayMenuConverter x:Key="ShouldDisplayMenu"/>
<Style TargetType="{x:Type igDP:HeaderPrefixArea}">

<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ig:XamMenu Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Converter={StaticResource ShouldDisplayMenu}}">
<ig:XamMenuItem Header="!">
<ig:XamMenuItem Header="Expand All" Click="XamMenuItem_Click"/>
</ig:XamMenuItem>
</ig:XamMenu>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDP:XamDataGrid.Resources>
</igDP:XamDataGrid>

<Button Content="Expand First Record" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10" Click="Button_Click"/>
</Grid>
</Window>

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Infragistics.Windows.DataPresenter;
using System.Collections.ObjectModel;

namespace ExapndAllMenu
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

Data = new ObservableCollection<Data>();

for (int i = 0; i < 10; i++)
{
Data d = new Data { Children = new ObservableCollection<Data>(), ID = i, Name = "Parent " + i };

if (i != 4)
for (int j = 0; j < 5; j++)
{
Data d1 = new Data { Children = new ObservableCollection<Data>(), ID = j, Name = "Child " + i + j };

for (int p = 0; p < 5; p++)
{
d1.Children.Add(new Data { ID = p, Name = "Child " + j + p });
}

d.Children.Add(d1);
}

Data.Add(d);
}

DataContext = this;
}

public ObservableCollection<Data> Data { get; set; }

private void XamMenuItem_Click(object sender, EventArgs e)
{
xamDataGrid1.Records.ExpandAll(true);
}

private void Button_Click(object sender, RoutedEventArgs e)
{
xamDataGrid1.Records[0].IsExpanded = true;
}
}

public class ShouldDisplayMenuConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DataRecordPresenter rec = value as DataRecordPresenter;
if (rec != null)
{
if ((rec.Record as HeaderRecord).AttachedToRecord.ParentRecord == null)
return Visibility.Visible;
}

return Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}


public class Data
{
public int ID { get; set; }
public string Name { get; set; }
public ObservableCollection<Data> Children { get; set; }
}
}

Thank you.

ExapndAllMenu_.zip