Skip to content

Commit 49f6ad5

Browse files
authored
Merge branch 'master' into Kinnara-push
2 parents c3933cc + d6fe01e commit 49f6ad5

33 files changed

+491
-57
lines changed

.editorconfig

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
[*.cs]
2+
3+
# CA1416: Validate platform compatibility
4+
dotnet_diagnostic.CA1416.severity = none
5+
6+
[*.cs]
7+
#### Naming styles ####
8+
9+
# Naming rules
10+
11+
dotnet_naming_rule.private_or_internal_field_should_be__exampleidentifier.severity = suggestion
12+
dotnet_naming_rule.private_or_internal_field_should_be__exampleidentifier.symbols = private_or_internal_field
13+
dotnet_naming_rule.private_or_internal_field_should_be__exampleidentifier.style = _exampleidentifier
14+
15+
# Symbol specifications
16+
17+
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
18+
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
19+
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
20+
21+
# Naming styles
22+
23+
dotnet_naming_style._exampleidentifier.required_prefix = _
24+
dotnet_naming_style._exampleidentifier.required_suffix =
25+
dotnet_naming_style._exampleidentifier.word_separator =
26+
dotnet_naming_style._exampleidentifier.capitalization = camel_case
27+
csharp_indent_labels = one_less_than_current
28+
csharp_using_directive_placement = outside_namespace:silent
29+
csharp_prefer_simple_using_statement = true:suggestion
30+
csharp_prefer_braces = true:silent
31+
csharp_style_namespace_declarations = block_scoped:silent
32+
csharp_style_prefer_method_group_conversion = true:silent
33+
csharp_style_expression_bodied_methods = false:silent
34+
csharp_style_expression_bodied_constructors = false:silent
35+
csharp_style_expression_bodied_operators = false:silent
36+
csharp_style_expression_bodied_properties = true:silent
37+
csharp_style_expression_bodied_indexers = true:silent
38+
csharp_style_expression_bodied_accessors = true:silent
39+
csharp_style_expression_bodied_lambdas = true:silent
40+
csharp_style_expression_bodied_local_functions = false:silent
41+
csharp_style_throw_expression = true:suggestion
42+
csharp_space_around_binary_operators = before_and_after
43+
csharp_style_prefer_null_check_over_type_check = true:suggestion
44+
csharp_prefer_simple_default_expression = true:suggestion
45+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
46+
csharp_style_prefer_index_operator = true:suggestion
47+
csharp_style_prefer_range_operator = true:suggestion
48+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
49+
csharp_style_prefer_tuple_swap = true:suggestion
50+
csharp_style_inlined_variable_declaration = true:suggestion
51+
csharp_style_deconstructed_variable_declaration = true:suggestion
52+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
53+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
54+
55+
[*.{cs,vb}]
56+
#### Naming styles ####
57+
58+
# Naming rules
59+
60+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
61+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
62+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
63+
64+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
65+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
66+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
67+
68+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
69+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
70+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
71+
72+
# Symbol specifications
73+
74+
dotnet_naming_symbols.interface.applicable_kinds = interface
75+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
76+
dotnet_naming_symbols.interface.required_modifiers =
77+
78+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
79+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
80+
dotnet_naming_symbols.types.required_modifiers =
81+
82+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
83+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
84+
dotnet_naming_symbols.non_field_members.required_modifiers =
85+
86+
# Naming styles
87+
88+
dotnet_naming_style.begins_with_i.required_prefix = I
89+
dotnet_naming_style.begins_with_i.required_suffix =
90+
dotnet_naming_style.begins_with_i.word_separator =
91+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
92+
93+
dotnet_naming_style.pascal_case.required_prefix =
94+
dotnet_naming_style.pascal_case.required_suffix =
95+
dotnet_naming_style.pascal_case.word_separator =
96+
dotnet_naming_style.pascal_case.capitalization = pascal_case
97+
98+
dotnet_naming_style.pascal_case.required_prefix =
99+
dotnet_naming_style.pascal_case.required_suffix =
100+
dotnet_naming_style.pascal_case.word_separator =
101+
dotnet_naming_style.pascal_case.capitalization = pascal_case
102+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
103+
tab_width = 4
104+
indent_size = 4
105+
end_of_line = crlf
106+
dotnet_style_coalesce_expression = true:suggestion
107+
dotnet_style_null_propagation = true:suggestion
108+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
109+
dotnet_style_prefer_auto_properties = true:silent
110+
dotnet_style_object_initializer = true:suggestion
111+
dotnet_style_collection_initializer = true:suggestion
112+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
113+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
114+
dotnet_style_prefer_conditional_expression_over_return = true:silent
115+
dotnet_style_explicit_tuple_names = true:suggestion
116+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
117+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
118+
dotnet_style_prefer_compound_assignment = true:suggestion
119+
dotnet_style_prefer_simplified_interpolation = true:suggestion
120+
dotnet_style_namespace_match_folder = true:suggestion
121+
dotnet_style_readonly_field = true:suggestion
122+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent

.github/workflows/build.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
name: Build
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ '**' ]
48

59
jobs:
610
build:
711

812
runs-on: windows-latest
913

1014
steps:
11-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
1216
- name: Setup .NET
13-
uses: actions/setup-dotnet@v1
17+
uses: actions/setup-dotnet@v2
1418
with:
1519
dotnet-version: 6.0.x
20+
- name: Setup Windows SDK
21+
uses: GuillaumeFalourd/[email protected]
1622
- name: Install dependencies
1723
run: dotnet restore
1824
- name: Build
1925
run: dotnet build --configuration Release --no-restore
26+
- name: Publish
27+
if: success() && github.ref_name == 'master' && github.event.head_commit.message == 'Bump version'
28+
run: |
29+
dotnet pack ModernWpf.Controls\ModernWpf.Controls.csproj -c Release --no-build
30+
dotnet nuget push "artifacts\*.nupkg" -k ${{ secrets.NUGET_API_KEY }}

Directory.Build.props

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Version>0.9.6</Version>
4+
<Authors>Yimeng Wu</Authors>
5+
<Product>ModernWPF UI Library</Product>
6+
<LangVersion>10.0</LangVersion>
7+
</PropertyGroup>
8+
</Project>

Directory.Build.targets

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<Authors>Yimeng Wu</Authors>
55
<Product>ModernWPF UI Library</Product>
66
</PropertyGroup>
7-
7+
88
<PropertyGroup Condition="'$(PackageId)' != ''">
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1010
<PackageProjectUrl>https://github.com/Kinnara/ModernWpf</PackageProjectUrl>
1111
<PackageTags>WPF XAML UI Theme Controls Fluent Modern Metro WinUI</PackageTags>
12-
<PackageOutputPath>$(MSBuildThisFileDirectory)localpackages</PackageOutputPath>
12+
<PackageOutputPath>$(MSBuildThisFileDirectory)artifacts</PackageOutputPath>
1313
</PropertyGroup>
1414

1515
<PropertyGroup Condition="'$(Configuration)'=='Release'">
@@ -43,7 +43,6 @@
4343
<PropertyGroup Condition="'$(SupportedOSPlatform)' != '' and $([MSBuild]::VersionGreaterThan($(SupportedOSPlatform), '7.0'))">
4444
<SupportedOSPlatform>7.0</SupportedOSPlatform>
4545
</PropertyGroup>
46-
4746
<Choose>
4847
<When Condition="'$(UseWinRT)' == 'true'">
4948
<Choose>

ModernWpf.Controls/AutoSuggestBox/AutoSuggestBoxTextChangedEventArgs.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Windows;
32

43
namespace ModernWpf.Controls
54
{

ModernWpf.Controls/ModernWpf.Controls.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetDocumentationFile</TargetsForTfmSpecificBuildOutput>
88
<NuspecFile>$(MSBuildThisFileDirectory)ModernWpfUI.nuspec</NuspecFile>
99
<PackageId>ModernWpfUI</PackageId>
10-
<LangVersion>latest</LangVersion>
1110
</PropertyGroup>
1211

1312
<ItemGroup>

ModernWpf.Controls/ModernWpfUI.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
<group targetFramework="netcoreapp3.0">
2424
<dependency id="Microsoft.Windows.SDK.Contracts" version="10.0.18362.2005" exclude="Build,Analyzers" />
2525
</group>
26-
<group targetFramework="net5.0-windows10.0.18362" />
26+
<group targetFramework="net5.0-windows7.0" />
2727
</dependencies>
2828
<frameworkReferences>
2929
<group targetFramework="netcoreapp3.0">
3030
<frameworkReference name="Microsoft.WindowsDesktop.App.WPF" />
3131
</group>
32-
<group targetFramework="net5.0-windows10.0.18362">
32+
<group targetFramework="net5.0-windows7.0">
3333
<frameworkReference name="Microsoft.WindowsDesktop.App.WPF" />
3434
</group>
3535
</frameworkReferences>

ModernWpf.MahApps/ModernWpf.MahApps.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<UseWPF>true</UseWPF>
66
<NeutralLanguage>en-US</NeutralLanguage>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8+
<NoWarn>1701;1702;1573;1591</NoWarn>
89
<PackageId>ModernWpfUI.MahApps</PackageId>
910
<Description>Styles to help integrate ModernWPF with MahApps.Metro.</Description>
1011
</PropertyGroup>

ModernWpf.SampleApp/ModernWpf.SampleApp.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<TargetFrameworks>net4.6.2</TargetFrameworks>
66
<UseWPF>true</UseWPF>
77
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
8-
<LangVersion>latest</LangVersion>
98
</PropertyGroup>
109

1110
<PropertyGroup>

ModernWpf.SampleApp/app.manifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
<application xmlns="urn:schemas-microsoft-com:asm.v3">
5454
<windowsSettings>
55-
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>
55+
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
5656
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
5757
</windowsSettings>
5858
</application>

ModernWpf.sln

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernWpf.Controls", "Moder
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1387DCAB-42A4-4F47-9E85-16998E2D9C71}"
1313
ProjectSection(SolutionItems) = preProject
14+
.editorconfig = .editorconfig
15+
Directory.Build.props = Directory.Build.props
1416
Directory.Build.targets = Directory.Build.targets
1517
EndProjectSection
1618
EndProject

ModernWpf/Common/DpiScale2.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Windows;
2+
3+
namespace ModernWpf
4+
{
5+
internal readonly record struct DpiScale2
6+
{
7+
public DpiScale2(double dpiScaleX, double dpiScaleY)
8+
{
9+
DpiScaleX = dpiScaleX;
10+
DpiScaleY = dpiScaleY;
11+
}
12+
13+
#if NET462_OR_NEWER
14+
public DpiScale2(DpiScale dpiScale)
15+
: this(dpiScale.DpiScaleX, dpiScale.DpiScaleY)
16+
{
17+
}
18+
#endif
19+
20+
public double DpiScaleX { get; }
21+
public double DpiScaleY { get; }
22+
}
23+
}

ModernWpf/Controls/Primitives/MaximizedWindowFixer.cs

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using MS.Win32;
2-
using Standard;
3-
using System;
4-
using System.Diagnostics;
1+
using System;
52
using System.Runtime.InteropServices;
63
using System.Windows;
74
using System.Windows.Controls;
85
using System.Windows.Interop;
9-
using System.Windows.Media;
6+
using MS.Win32;
7+
using Standard;
108
using NativeMethods = Standard.NativeMethods;
119

1210
namespace ModernWpf.Controls.Primitives
@@ -216,22 +214,12 @@ private Thickness GetMaximizedWindowBorder()
216214
return new Thickness();
217215
}
218216

219-
double dpiScaleX, dpiScaleY;
220-
#if NET462_OR_NEWER
221-
DpiScale dpi = VisualTreeHelper.GetDpi(_window);
222-
dpiScaleX = dpi.DpiScaleX;
223-
dpiScaleY = dpi.DpiScaleY;
224-
#else
225-
Matrix transformToDevice = _hwndSource.CompositionTarget.TransformToDevice;
226-
dpiScaleX = transformToDevice.M11;
227-
dpiScaleY = transformToDevice.M22;
228-
#endif
229-
217+
var dpi = _window.GetDpi();
230218
int frameWidth = NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME);
231219
int frameHeight = NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME);
232220
int borderPadding = NativeMethods.GetSystemMetrics(SM.CXPADDEDBORDER);
233221
Size borderSize = new Size(frameWidth + borderPadding, frameHeight + borderPadding);
234-
Size borderSizeInDips = DpiHelper.DeviceSizeToLogical(borderSize, dpiScaleX, dpiScaleY);
222+
Size borderSizeInDips = DpiHelper.DeviceSizeToLogical(borderSize, dpi.DpiScaleX, dpi.DpiScaleY);
235223

236224
return new Thickness(borderSizeInDips.Width, borderSizeInDips.Height, borderSizeInDips.Width, borderSizeInDips.Height);
237225
}

ModernWpf/Helpers/Helper.cs

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Windows;
4+
using System.Windows.Interop;
35
using System.Windows.Media;
46

57
namespace ModernWpf
@@ -80,6 +82,31 @@ public static bool HasLocalValue(this DependencyObject d, DependencyProperty dp)
8082
{
8183
return d.ReadLocalValue(dp) != DependencyProperty.UnsetValue;
8284
}
85+
86+
public static DpiScale2 GetDpi(this Window window)
87+
{
88+
if (window is null)
89+
{
90+
throw new ArgumentNullException(nameof(window));
91+
}
92+
93+
#if NET462_OR_NEWER
94+
return new DpiScale2(VisualTreeHelper.GetDpi(window));
95+
#else
96+
var hwnd = new WindowInteropHelper(window).Handle;
97+
var hwndSource = HwndSource.FromHwnd(hwnd);
98+
if (hwndSource != null)
99+
{
100+
Matrix transformToDevice = hwndSource.CompositionTarget.TransformToDevice;
101+
return new DpiScale2(transformToDevice.M11, transformToDevice.M22);
102+
}
103+
else
104+
{
105+
Debug.Fail("Should not reach here");
106+
return new DpiScale2(1, 1);
107+
}
108+
#endif
109+
}
83110
}
84111

85112
internal enum InterestPoint

ModernWpf/Helpers/OSVersionHelper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static class OSVersionHelper
2222

2323
public static bool IsWindows11OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(10, 0, 21996);
2424

25+
internal static bool IsWindows11OrGreater { get; } = IsWindowsNT && _osVersion >= new Version(10, 0, 22000);
26+
2527
private static Version GetOSVersion()
2628
{
2729
var osv = new RTL_OSVERSIONINFOEX();

ModernWpf/ModernWpf.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<NeutralLanguage>en-US</NeutralLanguage>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<LangVersion>latest</LangVersion>
10+
<NoWarn>1701;1702;1573;1591</NoWarn>
1011
</PropertyGroup>
1112

1213
<ItemGroup Condition="!$(DefineConstants.Contains('NET47_OR_NEWER'))">

ModernWpf/NativeMethods.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
WM_NCHITTEST
2+
WM_NCMOUSEMOVE
3+
WM_NCLBUTTONDOWN
4+
WM_NCLBUTTONUP
5+
WM_NCMOUSELEAVE
6+
HTCLIENT
7+
HTMAXBUTTON

ModernWpf/Standard/DpiHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static Point LogicalPixelsToDevice(Point logicalPoint, double dpiScaleX,
3333
/// <summary>
3434
/// Convert a point in system coordinates to a point in device independent pixels (1/96").
3535
/// </summary>
36-
/// <param name="logicalPoint">A point in the physical coordinate system.</param>
36+
/// <param name="devicePoint">A point in the physical coordinate system.</param>
3737
/// <returns>Returns the parameter converted to the device independent coordinate system.</returns>
3838
public static Point DevicePixelsToLogical(Point devicePoint, double dpiScaleX, double dpiScaleY)
3939
{

0 commit comments

Comments
 (0)