Skip to content

Commit

Permalink
Fix "WPF- OxyPlot doesn't render inside a Popup" (#1796) (#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetedeiench committed Oct 14, 2021
1 parent 02a21c5 commit e384904
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

### Fixed
- WPF - OxyPlot doesn't render inside a Popup (#1796)

## [2.1.0] - 2021-10-02

### Added
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Please keep the list sorted.

Adrien Mercier
Alexei Shcherbakov
Anders Musikka <anders@andersmusikka.se>
Auriou
Expand Down
1 change: 1 addition & 0 deletions Source/OxyPlot.WPF.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EdotCover_002EIde_002ECore_002EFilterManagement_002EModel_002ESolutionFilterSettingsManagerMigrateSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
8 changes: 8 additions & 0 deletions Source/OxyPlot.Wpf.Shared/PlotViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace OxyPlot.Wpf
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
Expand Down Expand Up @@ -451,6 +452,13 @@ private bool IsInVisualTree()
{
return true;
}

//Check if the logical parent is a popup. If so, we found the popuproot
var logicalRoot = LogicalTreeHelper.GetParent(dpObject);
if (logicalRoot is Popup)
{
return true;
}
}

return false;
Expand Down
19 changes: 11 additions & 8 deletions Source/OxyPlot.Wpf/PlotView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override double UpdateDpi()
{
var scale = base.UpdateDpi();
this.RenderContext.DpiScale = scale;
this.RenderContext.VisualOffset = this.TransformToAncestor(this.GetAncestorWindowFromVisualTree(this)).Transform(default);
this.RenderContext.VisualOffset = this.TransformToAncestor(this.GetAncestorVisualFromVisualTree(this)).Transform(default);
return scale;
}

Expand All @@ -146,18 +146,21 @@ private void DoCopy(object sender, ExecutedRoutedEventArgs e)


/// <summary>
/// Returns a reference to the window object that hosts the dependency object in the visual tree.
/// Returns a reference to the visual object that hosts the dependency object in the visual tree.
/// </summary>
/// <returns> The host window from the visual tree.</returns>
private Window GetAncestorWindowFromVisualTree(DependencyObject startElement)
private Visual GetAncestorVisualFromVisualTree(DependencyObject startElement)
{
DependencyObject parent = startElement;
while (!(parent is Window))

DependencyObject child = startElement;
DependencyObject parent = VisualTreeHelper.GetParent(child);
while (parent != null)
{
if (parent == null) { break; }
parent = VisualTreeHelper.GetParent(parent);
child = parent;
parent = VisualTreeHelper.GetParent(child);
}
return parent as Window ?? Window.GetWindow(this);

return child is Visual visualChild ? visualChild : Window.GetWindow(this);
}
}
}

0 comments on commit e384904

Please sign in to comment.