I want to display the a child table inside a xamdatagrid.
<igDP:XamDataGrid DataSource="{Binding DataContext.ViewSetList,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" > <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields>
<igDP:Field Name="PARAMETER"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="VALUE" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
I want to bind this <igDP:Field Name="VALUE" > field to another another data table. Is there any possible solutions
Hello AKshay,
Thank you for the code snippet you have provided.
You can use XamDataGrid’s Template Field to create a field with a custom display and edit template. In order to display the DataTable you will need some form of a Grid control. Using this approach I have created a small sample. You can use this as an example of the functionality of the Template Field, which Grid you will use depends solely on your scenario.
Hi NICK,
Thanks For the kind help.
I tried the above mentioned solution but not able to get results. So now i have used cell value presenter to display the table inside a table.
<Window x:Class="TestFast.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igEditors="http://infragistics.com/Editors" xmlns:local ="clr-namespace:TestFast" Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="TableData"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igDP:XamDataGrid DataSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <ItemsControl x:Name="MyItemContol" ItemsSource="{Binding ViewSetList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <ItemsControl.ItemTemplate> <DataTemplate>
<igDP:XamDataGrid DataSource="{Binding DataContext.ViewSetList,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" > <igDP:XamDataGrid.FieldLayouts > <igDP:FieldLayout> <igDP:FieldLayout.Fields>
<igDP:Field Name="VALUE" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource TableData}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="UNIT"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="INSTANCE"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field>
</igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
</DataTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </Grid></Window>
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using System.Threading.Tasks;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;
namespace TestFast{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { //private ObservableCollection<Parameters> viewSetList = new ObservableCollection<Parameters>(); //private ObservableCollection<Parameters> viewSetList = new ObservableCollection<Parameters>(); public ObservableCollection<Parameters> _ViewSetList = new ObservableCollection<Parameters>(); public MainWindow() { InitializeComponent(); DataTable table = new DataTable(); table.Columns.Add("Weight"); table.Columns.Add("Name"); table.Columns.Add("Breed"); table.Columns.Add("Date");
DataRow dt = null; int j = 0;
for (int i = 0; i < 3; i++) { dt = table.NewRow(); j = i; dt["Weight"] = j; dt["Name"] = j + 1; dt["Breed"] = j + 2; dt["Date"] = j + 3; table.Rows.Add(dt); }
ViewSetList.Add(new Parameters() { PARAMETER="abc", INSTANCE="def" , UNIT="hhshhd", VALUE= table}); //ViewSetList.Add(new Parameters() { PARAMETER = "abc2", INSTANCE="def2" , UNIT="hhshhd2", VALUE="hahha2" });
this.DataContext = this;
}
public ObservableCollection<Parameters> ViewSetList { set { _ViewSetList = value; } get { return _ViewSetList; } }
public class Parameters : INotifyPropertyChanged { private string parameterName = string.Empty;
public string PARAMETER { get { return parameterName; } set { parameterName = value; } } private DataTable parameterValue;
public DataTable VALUE { get { return parameterValue; } set { parameterValue = value; } } private string parameterUnit = string.Empty;
public string UNIT { get { return parameterUnit; } set { parameterUnit = value; } } private string instance = string.Empty;
public string INSTANCE { get { return instance; } set { instance = value; } }
public event PropertyChangedEventHandler PropertyChanged; private void onPropertyChanged(object sender, string propertyName) { if (this.PropertyChanged != null) { PropertyChanged(sender, new PropertyChangedEventArgs(propertyName)); } } }}
But the new problem is that it is showing same table inside that cell. But i want to bind only particular value to that cell?
I tried to use the
<igDP:XamDataGrid DataSource="{Binding Path=ViewSetList.Parameters.VALUE, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" />
But It is showing empty. Please help?
Thank you for the code you have provided.
I have modified the sample. Can you provide some information about your scenario? What is the functionality you want to achieve using ItemsControl?
I have bound the child XamDataGrid to the DataTable and it is inside a cell as you describe it. Can you take a look whether this is the functionality you want to achieve.
Hi Nick,
Thank you for the code. It has worked in the example application which you have provided. When i tried to implement the same in my application, i am just seeing the blank screen in that value Field. If i add a tag <autogeneratefields> it will display the columns likes [AddnewRecord location, Allow add new]
Here is the screen shot of the application
https://drive.google.com/open?id=1m2GMyUGg0zeyCyu1-F5sgWqYeAH3PZLn
Here is the code which i added
xaml file:
<DataTemplate x:Key="ViewSetTemplate" >
<igDP:XamDataGrid Height="Auto" ScrollViewer.VerticalScrollBarVisibility="Hidden" Theme="Office2010Blue" DataSource="{Binding ParameterList}" AutoFit="True" BorderBrush="DarkGray" BorderThickness="0.8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" GroupByAreaLocation="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden" > <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igEditors:XamTextEditor}"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields>
</igDP:Field> <igDP:Field Name="VALUE"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource downloadFileBtnStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="UNIT"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="INSTANCE"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="TABLEDATA"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource TableCellDisplay}"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="TABLE_DATATYPE" Visibility="Collapsed" />
<igDP:Field Name="DATATYPE" Visibility="Collapsed" /> <igDP:Field Name="PARAMCOLLAPSETYPE" Visibility="Collapsed" />
</igDP:FieldLayout.Fields> </igDP:FieldLayout>
</DataTemplate>
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="downloadFileBtnStyle">
<Style.Triggers> <DataTrigger Binding="{Binding Path=DataItem.DATATYPE, Converter={StaticResource DTChecker}}" Value="True"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Border BorderBrush="DarkGray" BorderThickness=".3,0,0,.3"> <DockPanel> <Button Style="{StaticResource btnStyle}" DockPanel.Dock="Right" Focusable="False" BorderThickness="0" FontWeight="Bold" ToolTip="Download File"> <Image Name="DownImage" Stretch="Fill" Source="../Resources/Images/arrow_down.png" /> <Button.DataContext> <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}" Path="DataContext"/> </Button.DataContext>
</Button> <ContentPresenter Content="{TemplateBinding Content}"/> </DockPanel> </Border> </DataTemplate> </Setter.Value> </Setter> </DataTrigger>
<DataTrigger Binding="{Binding Path=DataItem.DATATYPE, Converter={StaticResource DTChecker}}" Value="False"> <Setter Property="ContentTemplate"> <Setter.Value>
<DataTemplate> <Border BorderBrush="DarkGray" BorderThickness=".3,0,0,.3"> <DockPanel> <ContentPresenter Content="{TemplateBinding Content}"/> </DockPanel> </Border> </DataTemplate>
</Setter.Value> </Setter> </DataTrigger>
<DataTrigger Binding="{Binding Path=DataItem.TABLE_DATATYPE}" Value="True"> <Setter Property="Template"> <Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igDP:XamDataGrid DataSource="{Binding Path=ParameterList/TABLEDATA}"> </igDP:XamDataGrid> </ControlTemplate>
</Style.Triggers>
</Style> <Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="TableCellDisplay"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igDP:XamDataGrid DataSource="{Binding Path=ParameterList/TABLEDATA[0]}"> <igDP:FieldLayoutSettings AutoGenerateFields="True"/> </igDP:XamDataGrid> </ControlTemplate> </Setter.Value> </Setter>
</Style>
View model File
private ObservableCollection<ViewSet> viewSetList = new ObservableCollection<ViewSet>();
public ObservableCollection<ViewSet> ViewSetList { get { return viewSetList; } set { viewSetList = value; } }
public class ViewSet {
private ObservableCollection<Parameters> parameterList = new ObservableCollection<Parameters>();
//public ViewSet(string name) //{ // viewSetName = name; //} public ObservableCollection<Parameters> ParameterList { get { return parameterList; } set { parameterList = value; } } private string viewSetName = string.Empty; private string viewSetPriority = string.Empty; private bool expandViewSet = true;
// to control visibility of collapsed button present in viewset expander private bool showCollapsebutton = false;
public bool ShowViewCollapseButton { get { return showCollapsebutton; } set { showCollapsebutton = value; } }
public bool ExpandViewSet { get { return expandViewSet; } set { expandViewSet = value; } } public string ListViewSetName { get { return viewSetName; } set { viewSetName = value; } }
} public class Parameters { private string parameterName = string.Empty;
public string PARAMETER { get { return parameterName; } set { parameterName = value; } } private string parameterValue = string.Empty;
public string VALUE { get { return parameterValue; } set { parameterValue = value; } } private string parameterUnit = string.Empty;
private string datatype = string.Empty;
public string DATATYPE { get { return datatype; } set { datatype = value; } } private string table_datatype = string.Empty;
public string TABLE_DATATYPE { get { return table_datatype; } set { table_datatype = value; } }
private string paramCollapseType = string.Empty;
public string PARAMCOLLAPSETYPE { get { return paramCollapseType; } set { paramCollapseType = value; } }
private DataTable TableData = null;
public DataTable TABLEDATA { get { return TableData; } set { TableData = value; } } }
Why it is not displaying the table ? Is it the binding issue?
in xaml.cs file i am specifying data context
InitializeComponent(); this.DataContext = viewModel; viewRecipeViewvm = viewModel as ViewRecipeViewVM;
Hi nick,
I am using items control for one use case in my project.
Any update on this?