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
255
WPF- Not able to Bind XamDatagrid with observable collection
posted

i am  trying to bind  xamdatagrid to the observable collection.

<Grid> 
<ItemsControl x:Name="MyItemContol" ItemsSource="{Binding ViewSetList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> 
<ItemsControl.ItemTemplate>
 <DataTemplate>
 <igDP:XamDataGrid DataSource="{Binding ViewSetList}" > 
<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: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>
 </igDP:XamDataGrid>
 </DataTemplate> 
</ItemsControl.ItemTemplate> 
</ItemsControl> 
</Grid>


and my cs file will look like this


public partial class MainWindow : Window
{
           private ObservableCollection<Parameters> viewSetList = new ObservableCollection<Parameters>();
           public MainWindow()
           {
                InitializeComponent();

                viewSetList.Add(new Parameters() { PARAMETER="abc", INSTANCE="def" , UNIT="hhshhd", VALUE="hahha" }); 

            }

           public ObservableCollection<Parameters> ViewSetList
         {
          get { return viewSetList; }
          set
              {
              viewSetList = value;

               }
               }

}

public class Parameters: INotifyPropertyChanged
{
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;

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));
}
}
}