Hi,
I am working with XamGrid (I know it is recommended to move to XamDataGrid, but that's problematic for this specific grid).
The grid behaves weird when the data in the columns needs scrolling for some of the columns.
Once I select a line (using mouse) with a long text within one of the columns, the H-scroll jumps to the end of the grid.
When I scroll to the start and click on another line, which is shorter, the scroll sometimes jumps to the end and sometimes does not.
I've attached a sample class that shows this beahvior.
also I've added images:
1 - showing the state after selection of line X
2- showing the scroll I've manually changed, before selection of line Y (highlighted)
3 - showing the state after I've clicked on that line.
please advise how can I turn-off the scroll sauto-jump' behavior or any other workaround to solve this
Thanks
WPFChart.zip
I'm attaching an example that shows this issue.
as you can see, the style, with the preview-event-handler is defined as a resource of the grid.
a code creates a new conditional format style while using the original style as the 'basedon'.
exception is thrown.
this also occurs if I try to add the preview handler via code, when trying to define the style targettype of the 'basedon' as CellControl and not ConditionalFormattingCellControl.
when using the style in ConditionalFormattingCellControl that is new and not the original style - exception occurs. looks like some internal code that does not know how to cast EventSetter from the list of Setters.
Any idea?
Hello Eli,
As long as the “style” that you are setting there is a Style with it’s TargetType set to a ConditionalFormattingCellControl, this appears to be valid. It is possible that there is a bug in this area, since the XamGrid was originally designed for Silverlight where EventSetters didn’t exist, but I have yet to reproduce the exception you are seeing with this style?
It is possible that this could have to do with a specific type of conditional formatting, and I am missing that piece. Would it be possible for you to please provide some additional information about the conditional format you are applying or perhaps even an isolated sample project that demonstrates the exception you are seeing?
Please let me know if you have any other questions or concerns on this matter.
I have tried your suggestion in the simple example and it did the 'trick'.
however, the original XamGrid I'm using has conditional format for this problematic column.
when trying to add the 'preview' via code, I'm getting an exception when running it
style.Setters.Add(new EventSetter(ConditionalFormattingCellControl.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PreviewMouseDown)));
am I missing something? or this is not possible to add event-setter to conditional formatting cell?
Unable to cast object of type 'System.Windows.EventSetter' to type 'System.Windows.Setter'.
at Infragistics.Controls.Grids.ConditionalFormattingCell.ConditionalFormattingCellBindingConverter.MergeSettersIntoSingleStyle(List`1 setters, Style basedOnStyle, Boolean& controlTemplateSet, Boolean& needApplyStyle, ControlTemplate& controlTemplate) at Infragistics.Controls.Grids.ConditionalFormattingCell.ConditionalFormattingCellBindingConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange) at System.Windows.Data.BindingExpression.Activate(Object item) at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt) at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance) at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance) at MS.Internal.Data.DataBindEngine.Run(Object arg) at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() at System.Windows.ContextLayoutManager.UpdateLayout() at Infragistics.Controls.XamZoombar.UpdateElementPositions() at Infragistics.Controls.XamZoombar.HorizontalRootCanvas_SizeChanged(Object sender, SizeChangedEventArgs e) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.FrameworkElement.OnRenderSizeChanged(SizeChangedInfo sizeInfo) at System.Windows.ContextLayoutManager.fireSizeChangedEvents() at System.Windows.ContextLayoutManager.UpdateLayout() at Infragistics.Windows.DockManager.ContentPane.ActivateInternalImpl(Boolean force, Boolean bringIntoView, Boolean restoreMinimizedToolWindow) at Infragistics.Windows.DockManager.ContentPane.ActivateInternal(Boolean force, Boolean bringIntoView, Boolean restoreMinimizedToolWindow) at Infragistics.Windows.DockManager.ContentPane.Activate() at LogDog.Interactions.SessionsController.DisplayAnalysisOutput(Object sender, RunWorkerCompletedEventArgs e) in D:\Visual Studio Projects\Production\Tsm\LogPad\LogDog\Interactions\SessionsController.cs:line 470 at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at LogDog.App.Main()
I was also able to recreate the issue with a simple sample, and I attached it to development ID 273165 mentioned above so that our development teams will have it as well.
I have been investigating into a workaround, and the best thing I can recommend is to prevent the very large column from activating outright at the moment, as this will prevent the horizontal scrollbar from moving. In order to do this, you can write a Style for CellControl and use an EventSetter to hook the PreviewMouseDown event and mark it handled. The CellControl sender of that event will have a reference to the Cell and the Cell to the Row, which you can then mark selected.
Where you may run into issues here is if you want to allow editing of the large column, though. You may need to place the cell into edit mode programmatically, but this also will likely result in the scrolling issue because a cell needs to be active to go into edit mode, and the activation of the cell is what is scrolling the grid in this case.
I am attaching a sample project with a simple proposed workaround that handles the PreviewMouseDown event on CellControl and just marks the Row selected instead of allowing activation of the cells.
XamGridLongColumnScrollingTest.zip