Reputation: 679
Edit: I have already looked at the Infragistics forums. The code below is based on their samples. The data binding just doesn't seem to work.
I have an Infragistics XamDataGrid in my view.
<DockPanel>
<grid:XamDataGrid x:Name="gridData" DataContext="{Binding Path=DataEditorDataTable}" DataSource="{Binding Path=DataEditorDataTable.DefaultView}"
IsSynchronizedWithCurrentItem="True" Visibility="{Binding DataGridVisible}">
<grid:XamDataGrid.FieldLayoutSettings>
<grid:FieldLayoutSettings AutoGenerateFields="True" AllowAddNew="False" AllowDelete="False" />
</grid:XamDataGrid.FieldLayoutSettings>
</grid:XamDataGrid>
</DockPanel>
I set the data context for the user control in the constructor.
public DataEditor(SomeDataType DataType, IEventAggregator eventaggregator)
{
InitializeComponent();
this.DataContext = new DataEditorViewModel(DataType, eventaggregator);
}
In the dataeditor view model, I subscribe to an event that lets me know when data has changed and I build a datatable and call a method SetData. (I cannot know ahead how many columns of data are going to be shown in the grid, and these columns keep changing with user interaction, so I am hoping to use the data table to bind.)
I assign the properties in a method like so.
/// <summary>
/// Returns the data that the data editor displays.
/// </summary>
public DataTable DataEditorDataTable
{
get
{
return dtDataEditor;
}
set
{
dtDataEditor = value;
OnPropertyChanged("DataEditorDataTable");
}
}
/// <summary>
/// Method to set data on load
/// </summary>
private void SetData(DataTable dtDataEditor)
{
if (!isDataEditorCellEdited)
if (dtDataEditor != null && dtDataEditor.Rows.Count > 0)
{
try
{
//Assign the data to the grid
DataEditorDataTable = dtDataEditor;
DataGridVisible = Visibility.Visible;
}
catch
{
//If any exception occurs, hide the grid
DataGridVisible = Visibility.Collapsed;
}
}
else
//If no data, hide the grid
DataGridVisible = Visibility.Collapsed;
}
The problem is that the binding is simply not happening. Is there anything in particular I have missed with regard to the bindings?
Upvotes: 1
Views: 2769
Reputation: 3228
For debugging the binding errors you should look at the output window in visual studio to see if there are any errors.
Reading the code that you have, I assume that the binding is incorrect and should be:
DataContext="{Binding Path=DataEditorDataTable}" DataSource="{Binding Path=DefaultView}"
The change that I made was to remove the property from the table from the path of the DataSource since the table is already the DataContext and you want to bind to the DefaultView off of the table.
Upvotes: 2