Skip to content

Commit

Permalink
BitmapCache-related improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Mar 30, 2020
1 parent dcae0da commit 0777892
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ModernWpf.Controls/Flyout/Flyout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void PlayOpenAnimation()
#if NETCOREAPP || NET462
var bitmapCache = new BitmapCache(VisualTreeHelper.GetDpi(presenter).PixelsPerDip);
#else
var bitmapCache = new BitmapCache();
var bitmapCache = s_bitmapCacheMode;
#endif
presenter.CacheMode = bitmapCache;
}
Expand Down
11 changes: 10 additions & 1 deletion ModernWpf.MahApps/HamburgerMenu/HamburgerMenuEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class HamburgerMenuEx : HamburgerMenu
private static readonly PropertyPath _scaleYPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)");
private static readonly PropertyPath _translateYPath = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)");

private static readonly BitmapCache _bitmapCacheMode = new BitmapCache();
private readonly BitmapCache _bitmapCacheMode = new BitmapCache();

private UIElement _paneGrid;
private Button _paneSearchButton;
Expand Down Expand Up @@ -506,6 +506,15 @@ public override void OnApplyTemplate()
ChangeItemFocusVisualStyle();
}

#if NETCOREAPP || NET462
protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)
{
base.OnDpiChanged(oldDpi, newDpi);

_bitmapCacheMode.RenderAtScale = newDpi.PixelsPerDip;
}
#endif

private static void OnDisplayModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((HamburgerMenuEx)d).OnDisplayModeChanged(e);
Expand Down
2 changes: 1 addition & 1 deletion ModernWpf/Transitions/TransitionFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private static void CompleteTransition(NavigationTransition navigationTransition
/// <param name="presenter">The content presenter instance.</param>
/// <param name="applyBitmapCache">A value indicating whether to apply
/// a bitmap cache.</param>
private static void PrepareContentPresenterForCompositor(ContentPresenter presenter, bool applyBitmapCache = true)
private static void PrepareContentPresenterForCompositor(ContentPresenter presenter, bool applyBitmapCache = false)
{
if (presenter != null)
{
Expand Down
4 changes: 4 additions & 0 deletions ModernWpf/Transitions/Transitions/Transition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ private void Save()
_cacheMode = _element.CacheMode;
if (!(_cacheMode is BitmapCache))
{
#if NETCOREAPP || NET462
_element.CacheMode = new BitmapCache(VisualTreeHelper.GetDpi(_element).PixelsPerDip);
#else
_element.CacheMode = TransitionFrame.BitmapCacheMode;
#endif
}
_isHitTestVisible = _element.IsHitTestVisible;
if (_isHitTestVisible)
Expand Down

0 comments on commit 0777892

Please sign in to comment.