You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"The specified Visual is not an ancestor of this Visual" exception in OxySKElement.OnRender() #1787
We use a docking manager in our application. With it it's possible to dock out windows with plots and arrange them on another screens.
With the current oxyplot version and OxyPlot.SkiaSharp.Wpf.PlotView, we get an exception after undocking a window with a plot.
Partial stack-trace:
System.InvalidOperationException
HResult=0x80131509
Message=The specified Visual is not an ancestor of this Visual.
Source=PresentationCore
StackTrace:
at System.Windows.Media.Visual.TrySimpleTransformToAncestor(Visual ancestor, Boolean inverse, GeneralTransform& generalTransform, Matrix& simpleTransform)
at System.Windows.Media.Visual.TransformToAncestor(Visual ancestor)
at OxyPlot.SkiaSharp.Wpf.OxySKElement.OnRender(DrawingContext drawingContext)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
...
[Call Stack Truncated]
This exception was originally thrown at this call stack:
System.Windows.Media.Visual.TrySimpleTransformToAncestor(System.Windows.Media.Visual, bool, out System.Windows.Media.GeneralTransform, out System.Windows.Media.Matrix)
System.Windows.Media.Visual.TransformToAncestor(System.Windows.Media.Visual)
OxyPlot.SkiaSharp.Wpf.OxySKElement.OnRender(System.Windows.Media.DrawingContext)
System.Windows.UIElement.Arrange(System.Windows.Rect)
System.Windows.Controls.Grid.ArrangeOverride(System.Windows.Size)
System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
System.Windows.UIElement.Arrange(System.Windows.Rect)
System.Windows.Controls.Border.ArrangeOverride(System.Windows.Size)
System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
System.Windows.UIElement.Arrange(System.Windows.Rect)
...
[Call Stack Truncated]
Steps to reproduce
Use a docking manager like syncfusion DockingManger
Undock the window with the plot, so that the window with the PlotView is no longer a descendant of the MainWindow in the VisualTree .
VisualTree of the Application with floating window:
Platform: x86 & x64
.NET version: 4.7.2
Latest OxyPlot Version (nuget packages build from develop brunch)
Actual behaviour
The call Window.GetWindow(this) in OxySKElement.OnRender() returns always the MainWindow. I think it uses the logical tree not the visual tree and this.TransformToAncestor() fails, because the MainWindow is actually not an ancestor of the plot in case of a floating window.
Possible Fix
Get the ancestor from the visual tree with a methode like this
private Window GetAncestorWindowFromVisualTree(DependencyObject startElement)
{
DependencyObject parent = startElement;
while (!(parent is Window))
{
if (parent == null) { break; }
parent = VisualTreeHelper.GetParent(parent);
}
return parent as Window ?? Window.GetWindow(this);
}
var visualOffset = this.TransformToAncestor(GetAncestorWindowFromVisualTree(this)).Transform(default);
Yes, that's right. I've tested it, it has the same issue.
We've updated from a quite old version.
Version f9cebf3 from 2019-01-31 didn't have this issue.
Activity
VisualMelon commentedon Sep 8, 2021
Same code is used in the non-Skia WPF PlotView: https://github.com/oxyplot/oxyplot/blob/develop/Source/OxyPlot.Wpf/PlotView.cs#L131
albtaeler commentedon Sep 8, 2021
Yes, that's right. I've tested it, it has the same issue.
We've updated from a quite old version.
Version f9cebf3 from 2019-01-31 didn't have this issue.
VisualMelon commentedon Sep 8, 2021
Thanks for reporting and checking that. It's been a while since I had to understand WPF, but I'll try to get my head around this.
If you wanted to submit a PR, I'd be happy to review it; otherwise, I'll try to sort one out over the weekend.
This is presumably then a significant regression with 2.1 which we should address before publishing.
Fix "The specified Visual is not an ancestor of this Visual" exception (
Update the change log for issue oxyplot#1787
Fix "The specified Visual is not an ancestor of this Visual" exception (
Fix "The specified Visual is not an ancestor of this Visual" exception (
Fix "The specified Visual is not an ancestor of this Visual" exception (