Skip to content

Commit 89fe988

Browse files
committed
Respect system settings for transparency effects and automatically hiding scroll bars (#167)
1 parent cba42fb commit 89fe988

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

ModernWpf.SampleApp/App.xaml

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
</ui:ThemeResources>
4444

4545
<ui:XamlControlsResources />
46-
<sc:UISettingsResources />
4746

4847
<!-- Font Overrides -->
4948
<!--<sc:FontOverrides FontFamily="Comic Sans MS" />-->

ModernWpf/Controls/XamlControlsResources.cs

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class XamlControlsResources : ResourceDictionary
1313
public XamlControlsResources()
1414
{
1515
MergedDictionaries.Add(ControlsResources);
16+
MergedDictionaries.Add(UISettingsResources);
1617

1718
if (DesignMode.DesignModeEnabled)
1819
{
@@ -65,8 +66,17 @@ internal static ResourceDictionary CompactResources
6566
}
6667
}
6768

69+
internal static ResourceDictionary UISettingsResources
70+
{
71+
get
72+
{
73+
return _uiSettingsResources ??= new UISettingsResources();
74+
}
75+
}
76+
6877
private static ResourceDictionary _controlsResources;
6978
private static ResourceDictionary _compactResources;
79+
private static ResourceDictionary _uiSettingsResources;
7080

7181
private bool _useCompactResources;
7282
}

samples/SamplesCommon/UISettingsResources.cs ModernWpf/UISettingsResources.cs

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using System;
2-
using System.ComponentModel;
3-
using System.Runtime.CompilerServices;
1+
using System.Runtime.CompilerServices;
42
using System.Windows;
53
using System.Windows.Threading;
64
using Windows.Foundation.Metadata;
75
using Windows.UI.ViewManagement;
86

9-
namespace SamplesCommon
7+
namespace ModernWpf
108
{
11-
public class UISettingsResources : ResourceDictionary
9+
internal class UISettingsResources : ResourceDictionary
1210
{
1311
private const string UniversalApiContractName = "Windows.Foundation.UniversalApiContract";
1412
private const string AutoHideScrollBarsKey = "AutoHideScrollBars";
@@ -17,23 +15,20 @@ public class UISettingsResources : ResourceDictionary
1715

1816
public UISettingsResources()
1917
{
20-
if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
18+
if (DesignMode.DesignModeEnabled)
2119
{
22-
if (Environment.OSVersion.Version.Major >= 10)
23-
{
24-
Initialize();
25-
}
20+
return;
21+
}
22+
23+
if (OSVersionHelper.IsWindows10)
24+
{
25+
Initialize();
2626
}
2727
}
2828

2929
[MethodImpl(MethodImplOptions.NoInlining)]
3030
private void Initialize()
3131
{
32-
if (_uiSettings != null)
33-
{
34-
return;
35-
}
36-
3732
var uiSettings = new UISettings();
3833

3934
if (ApiInformation.IsApiContractPresent(UniversalApiContractName, 4))
@@ -75,11 +70,6 @@ private void InitializeForContract8(UISettings settings)
7570
ApplyAutoHideScrollBars(settings.AutoHideScrollBars);
7671
}
7772

78-
private void ApplyAutoHideScrollBars(bool value)
79-
{
80-
this[AutoHideScrollBarsKey] = value;
81-
}
82-
8373
private void ApplyAdvancedEffectsEnabled(bool value)
8474
{
8575
var key = SystemParameters.DropShadowKey;
@@ -92,5 +82,10 @@ private void ApplyAdvancedEffectsEnabled(bool value)
9282
this[key] = false;
9383
}
9484
}
85+
86+
private void ApplyAutoHideScrollBars(bool value)
87+
{
88+
this[AutoHideScrollBarsKey] = value;
89+
}
9590
}
9691
}

samples/FluentRibbonSample/App.xaml

-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:ui="http://schemas.modernwpf.com/2019"
6-
xmlns:local="clr-namespace:FluentRibbonSample"
7-
xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
86
StartupUri="MainWindow.xaml">
97
<Application.Resources>
108
<ResourceDictionary>
119
<ResourceDictionary.MergedDictionaries>
1210
<ui:ThemeResources RequestedTheme="Light" />
1311
<ui:XamlControlsResources />
1412
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Generic.xaml" />
15-
<sc:UISettingsResources />
1613
</ResourceDictionary.MergedDictionaries>
1714
</ResourceDictionary>
1815
</Application.Resources>

samples/FluentWPFSample/App.xaml

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:ui="http://schemas.modernwpf.com/2019"
6-
xmlns:local="clr-namespace:FluentWPFSample"
7-
xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
86
StartupUri="MainWindow.xaml">
97
<Application.Resources>
108
<ResourceDictionary>
@@ -37,7 +35,6 @@
3735
<!-- ModernWPF controls resources -->
3836
<ui:XamlControlsResources />
3937

40-
<sc:UISettingsResources />
4138
</ResourceDictionary.MergedDictionaries>
4239

4340
</ResourceDictionary>

samples/MahAppsSample/App.xaml

-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:ui="http://schemas.modernwpf.com/2019"
66
xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
7-
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
8-
xmlns:local="clr-namespace:MahAppsSample"
9-
xmlns:sys="clr-namespace:System;assembly=mscorlib"
107
StartupUri="MainWindow.xaml">
118
<Application.Resources>
129
<ResourceDictionary>
@@ -33,7 +30,6 @@
3330
<ui:XamlControlsResources />
3431
<ResourceDictionary Source="/ModernWpf.MahApps;component/Styles/Controls.xaml" />
3532

36-
<sc:UISettingsResources />
3733
</ResourceDictionary.MergedDictionaries>
3834

3935
<Style TargetType="ScrollViewer" BasedOn="{StaticResource DefaultScrollViewerStyle}">

0 commit comments

Comments
 (0)