Hi:
I am getting the following exception when underlying datasource is changed. Help!!! I am using Model-View-Presenter pattern and setting datacontext for the page. Data is displayed correctly first time ( No Exceptions) and when i change the underying datasource in response to a menuitem i get the exception
Thanks
David
Xaml fragment for the grid is as follows
<igDP:XamDataGrid Margin="0,32,0,0" x:Name="igGridDocuments" Style="{StaticResource readOnlyGrid}" DataSource="{Binding Path=Requests.Tables[0]}">
DataContext is set as follows
{
InitializeComponent();
CommandBindingCollection commandBindings = _viewModel.CommandBindings;
this.DataContext = _viewModel;
}
Exception
---------------------------Unhandled Exception---------------------------System.InvalidOperationException: Must call EndGeneration before calling BeginGeneration again.
at Infragistics.Windows.Virtualization.RecyclingItemContainerGenerator.BeginGeneration(ScrollDirection scrollDirection)
at Infragistics.Windows.Virtualization.RecyclingItemsPanel.BeginGeneration(ScrollDirection scrollDirection)
at Infragistics.Windows.DataPresenter.GridViewPanel.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
at System.Windows.Controls.Control.MeasureOverride(Size constraint)
at Infragistics.Windows.DataPresenter.RecordListControl.MeasureOverride(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)
at System.Windows.Controls.Page.MeasureOverride(Size constraint)
at System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
at System.Windows.Window.MeasureOverrideHelper(Size constraint)
at System.Windows.Window.MeasureOverride(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)---------------------------OK ---------------------------
Thanks Joe , Philipp . I am using 7.2 controls. Philipp is correct these exceptions are popping out like mad and it turned out to be an editor style using a value convertor to display User Names from UserIds. Once i remove this editor style i do not get these exceptions, . I am using ValueConverters with other fields ( all of them happened to be DataType String ) while UserId is an int32. For now i have removed the editor style to kepp moving.
Relavant XAML fragments
<Page.Resources>
<vw:DocumentStatusConverter x:Key="documentStatusConverter" />
<vw:RequestStatusConverter x:Key="requestStatusConverter" />
<vw:UserIdConverter x:Key="userIdConverter" />
<vw:DateRangeConverter x:Key="dateRangeConverter" />
<igDP:Field Name="ASSIGNED_TO" Label="User" DataType="System:Int32">
<igDP:Field.Settings>
<igDP:FieldSettings CellWidth="200" LabelWidth="120" >
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamTextEditor}" >
<Setter Property="ValueToDisplayTextConverter" Value="{StaticResource userIdConverter}"/>
<Setter Property="ValueToTextConverter" Value="{StaticResource userIdConverter}"/>
</Style>
</igDP:FieldSettings.EditorStyle>
-->
</igDP:FieldSettings>
</igDP:Field.Settings>
<igDP:Field Name="STATUS" Label="Status" DataType="System:String">
<igDP:FieldSettings CellWidth="200" LabelWidth="200">
<Setter Property="ValueToDisplayTextConverter" Value="{StaticResource requestStatusConverter}"/>
<Setter Property="ValueToTextConverter" Value="{StaticResource requestStatusConverter}"/>
</igDP:Field>
Hi David,
I'm not sure why a value converter would create the kind of exception call stack that you posted originally. Can you post the value converter code so I can try it out here.
Thanks,Sandip
Hi Sandip:
I can reproduce the exception consistently with above call stack when editror syle is uncommented. I am posting the code for value converter and static class value converter is calling
public class UserIdConverter : IValueConverter
// Convert gets called to convert value to text.
string userName = string.Empty;
// ConvertBack gets called to convert user input into to value.
int userId = -100;
--- Code for SecurityService class is as follows
using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Windows;using System.Windows.Controls;using VistaSG.Common;using VistaSG.Security.DataContracts;
namespace VistaSG.ReviewClient{
public static class SecurityService {
private static CustomClientChannel<VistaSG.Security.Services.IUser> _serviceChannel = null; private static VistaSG.Security.Services.IUser _serviceClient = null;
private static DataSet _userNames = null;
public static void InitializeComponent() { if (_serviceChannel == null) { _serviceChannel = new CustomClientChannel<VistaSG.Security.Services.IUser>("UserService", ConfigurationOptionsService.ServiceConfigurationFileName); if (_serviceChannel != null) { _serviceClient = _serviceChannel.CreateChannel(); }
public static void DisposeComponent() { if (_serviceChannel != null) { _serviceChannel.Close(); _serviceChannel = null; }
public static DataSet GetUsers() { DataSet ds = GetUsers(true); return ds; }
public static DataSet GetUsers(bool includeCommonUser) { DataSet ds = null; try { if (_userNames == null) { InitializeComponent(); string userXml = _serviceClient.GetUsers(); if (userXml.Length > 0) { ds = UtiltyMethods.GetDataSetFromString(userXml); if (includeCommonUser && ds != null && ds.Tables.Count > 0) { DataRow newUserRow = ds.Tables[0].NewRow(); newUserRow.BeginEdit(); newUserRow["USER_ID"] = -1; newUserRow["DISPLAY_NAME"] = "COMMON"; newUserRow.EndEdit(); ds.Tables[0].Rows.InsertAt(newUserRow, 0); ds.AcceptChanges(); } } if (ds != null && ds.Tables.Count > 0) { _userNames = ds; } } else { ds = _userNames; }
} catch (Exception ex) { MessageBox.Show(ex.ToString(), "Get Users", MessageBoxButton.OK, MessageBoxImage.Error);
} return ds; }
public static string GetUserName(int userId) { string userName = string.Empty; try { // if we can't find userid we will simply return id as name userName = userId.ToString(); GetUsers(true); if ( _userNames != null && _userNames.Tables.Count > 0 && _userNames.Tables[0].Rows.Count > 0 ) { DataRow dr = _userNames.Tables[0].Rows.Find(userId ) ; if (dr != null) { userName = Convert.ToString(dr["DISPLAY_NAME"]); } }
} catch (Exception ex) { MessageBox.Show(ex.ToString(), "Get User Name", MessageBoxButton.OK, MessageBoxImage.Error);
} return userName; }
public static int GetUserId(string userName) { int userId = -100; try { GetUsers(true); if (_userNames != null && _userNames.Tables.Count > 0 && _userNames.Tables[0].Rows.Count > 0) { string filterExpression = "DISPLAY_NAME='" + userName + "'"; DataRow[ matchingRows = _userNames.Tables[0].Select(filterExpression); if ( matchingRows != null && matchingRows.Length > 0 ) { userId = Convert.ToInt32(matchingRows[0]["USER_ID"]); }
} catch (Exception ex) { MessageBox.Show(ex.ToString(), "Get User Id", MessageBoxButton.OK, MessageBoxImage.Error);
} return userId ; }
}}
Have you tried setting a break point in the converter? If the conversion causes the error, you will get the source of the problem in debug mode as the BeginGeneration exceptions just occur if the exception hits through...