Skip to content

Commit

Permalink
Get initial dpi before first window open
Browse files Browse the repository at this point in the history
  • Loading branch information
stnkl committed Jan 26, 2023
1 parent 1f8af7a commit 0c8899a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions EverythingToolbar.Deskband/WindowPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace EverythingToolbar.Behaviors
internal class SearchWindowPlacement : Behavior<SearchWindow>
{
// Using a dependency property for binding is not required since the placement target will not change
public UIElement PlacementTarget;
public FrameworkElement PlacementTarget;

private double DpiScalingFactor;

Expand All @@ -26,10 +26,11 @@ protected override void OnAttached()

AssociatedObject.Showing += OnShowing;
AssociatedObject.Hiding += OnHiding;
AssociatedObject.Loaded += OnLoaded;

PlacementTarget.Loaded += OnPlacementTargetLoaded;
}

private void OnLoaded(object sender, RoutedEventArgs e)
private void OnPlacementTargetLoaded(object sender, RoutedEventArgs e)
{
DpiScalingFactor = GetScalingFactor();
}
Expand Down Expand Up @@ -92,7 +93,7 @@ private Size GetTargetWindowSize()

private double GetScalingFactor()
{
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(AssociatedObject)).Handle;
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(PlacementTarget)).Handle;
return 96.0 / GetDpiForWindow(hwnd);
}

Expand Down

0 comments on commit 0c8899a

Please sign in to comment.