I'm having some issues with FixedDocument & FixedPage content. I've found a work around that works for me, but I would much rather not have to use the work around. First off, I'm creating some FixedPage's from loaded UserControls (created from a loose xaml file). The Xaml files are basically template, and implement data binding.
Now, everything works mostly as expected. Except for one problematic template. This template uses an ItemsControl, a DataContext (provided in code at runtime), and a DataTemplate. This UserControl, when added to a FixedPage, works. t shows up as expected, with all the items in the ItemsControl according to the template. However, the DataTemplate has a Image in it. This Image is causing a null exception in LogicalTreeHelper.GetChildren() whenever the mouse moves over the image. The work around I used is to simply use a Rectangle with an ImageBrush to display the image. This is not ideal, because it places an odd restriction on the otherwise powerful WPF Xaml templates, and also the Rectangle does not scale to correct dimensions like a Image object can.
Anyway, the problem lies in that the FixedPage is trying to get the Logical Parent (as seen from looking at the symbols) of the Image. Which it does find a Grid item... but when trying to get the parent of the Grid, it is Null (whereas a normal Image not in the DataTemplate will have the top level control, and then the FixedPage as its grandparent). It seems that there is a problem with FixedPage's - or something that needs to be documented somewhere. Feedback is appreciated.
The stack trace is pretty big, but here it is:
Now, everything works mostly as expected. Except for one problematic template. This template uses an ItemsControl, a DataContext (provided in code at runtime), and a DataTemplate. This UserControl, when added to a FixedPage, works. t shows up as expected, with all the items in the ItemsControl according to the template. However, the DataTemplate has a Image in it. This Image is causing a null exception in LogicalTreeHelper.GetChildren() whenever the mouse moves over the image. The work around I used is to simply use a Rectangle with an ImageBrush to display the image. This is not ideal, because it places an odd restriction on the otherwise powerful WPF Xaml templates, and also the Rectangle does not scale to correct dimensions like a Image object can.
Anyway, the problem lies in that the FixedPage is trying to get the Logical Parent (as seen from looking at the symbols) of the Image. Which it does find a Grid item... but when trying to get the parent of the Grid, it is Null (whereas a normal Image not in the DataTemplate will have the top level control, and then the FixedPage as its grandparent). It seems that there is a problem with FixedPage's - or something that needs to be documented somewhere. Feedback is appreciated.
The stack trace is pretty big, but here it is:
> PresentationFramework.dll!System.Windows.LogicalTreeHelper.GetChildren(System.Windows.DependencyObject current) Line 161 + 0x2c bytes C# |
PresentationFramework.dll!System.Windows.Documents.FixedPage._CreateChildIndex(System.Windows.DependencyObject e = {System.Windows.Controls.Grid}) Line 1066 C# |
PresentationFramework.dll!System.Windows.Documents.FixedTextView.GetTextPositionFromPoint(System.Windows.Point point, bool snapToText = true) Line 113 + 0x1e bytes C# |
PresentationFramework.dll!MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(System.Windows.Point point, bool snapToText) Line 471 + 0x19 bytes C# |
PresentationFramework.dll!MS.Internal.Documents.DocumentPageTextView.GetTextPositionFromPoint(System.Windows.Point point, bool snapToText) Line 113 + 0x1f bytes C# |
PresentationFramework.dll!MS.Internal.Documents.MultiPageTextView.GetTextPositionFromPoint(System.Windows.Point point, bool snapToText) Line 110 + 0x19 bytes C# |
PresentationFramework.dll!MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(System.Windows.Point point, bool snapToText) Line 471 + 0x19 bytes C# |
PresentationFramework.dll!System.Windows.Documents.TextEditorMouse.IsPointWithinInteractiveArea(System.Windows.Documents.TextEditor textEditor, System.Windows.Point point) Line 157 C# |
PresentationFramework.dll!System.Windows.Documents.TextEditorMouse.OnQueryCursor(object sender, System.Windows.Input.QueryCursorEventArgs e = {System.Windows.Input.QueryCursorEventArgs}) Line 409 + 0x22 bytes C# |
PresentationCore.dll!System.Windows.Input.QueryCursorEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 62 C# |
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Line 341 + 0x8 bytes C# |
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Line 81 C# |
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Image}, System.Windows.RoutedEventArgs args = {System.Windows.Input.QueryCursorEventArgs}, bool reRaised = false) Line 205 C# |
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Image}, System.Windows.RoutedEventArgs args = {System.Windows.Input.QueryCursorEventArgs}) Line 2090 + 0x11 bytes C# |
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.QueryCursorEventArgs}, bool trusted) Line 474 + 0x5 bytes C# |
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Line 798 C# |
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Line 563 C# |
PresentationCore.dll!System.Windows.Input.MouseDevice.UpdateCursorPrivate() Line 1024 C# |
PresentationCore.dll!System.Windows.Input.MouseDevice.PostProcessInput(object sender, System.Windows.Input.ProcessInputEventArgs e) Line 2103 + 0x1d bytes C# |
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Line 833 + 0xe bytes C# |
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Line 563 C# |
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Line 125 + 0xf bytes C# |
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) Line 1359 C# |
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 658124, int msg = 512, System.IntPtr wParam = 0, System.IntPtr lParam = 18285240, ref bool handled = false) Line 490 + 0x1b bytes C# |
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 658124, int msg = 512, System.IntPtr wParam = 0, System.IntPtr lParam = 18285240, ref bool handled = false) Line 1626 C# |
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 658124, int msg = 512, System.IntPtr wParam = 0, System.IntPtr lParam = 18285240, ref bool handled = false) Line 342 + 0x15 bytes C# |
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Line 496 + 0x18 bytes C# |
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = {System.Object DispatcherCallbackOperation(System.Object)}}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) Line 91 + 0x2d bytes C# |
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) Line 21 + 0x15 bytes C# |
WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) Line 2277 + 0x29 bytes C# |
WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) Line 843 + 0x30 bytes C# |
WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) Line 599 + 0x30 bytes C# |
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 658124, int msg = 512, System.IntPtr wParam = 0, System.IntPtr lParam = 18285240) Line 400 C# |
[Native to Managed Transition] |
[Managed to Native Transition] |
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame}) Line 1597 + 0x38 bytes C# |
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Line 335 C# |
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() Line 294 C# |
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Line 2702 C# |
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Line 1851 C# |
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) Line 260 + 0x9 bytes C# |
PresentationFramework.dll!System.Windows.Application.Run() Line 221 + 0x13 bytes C# |
XamlTemplate.exe!XamlTemplate.App.Main() + 0x5e bytes C# |
[Native to Managed Transition] |
[Managed to Native Transition] |
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Line 931 + 0x1f bytes C# |
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes |
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Line 61 + 0xffffffe3 bytes C# |
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 355 + 0xd bytes C# |
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Line 88 + 0xffffffe4 bytes C# |