Skip to content

Commit

Permalink
删除 HasStatusBar
Browse files Browse the repository at this point in the history
更新 C#/WinRT
  • Loading branch information
wherewhere committed Aug 12, 2024
1 parent 7be6348 commit 87feae3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion MicaDemo/Common/ExceptionHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private bool HandleException(Exception exception)
{
if (UnhandledException == null) { return false; }

UnhandledExceptionEventArgs exWrapper = new UnhandledExceptionEventArgs()
UnhandledExceptionEventArgs exWrapper = new UnhandledExceptionEventArgs
{
Exception = exception
};
Expand Down
7 changes: 5 additions & 2 deletions MicaDemo/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Metadata;
using Windows.UI;
using Windows.UI.ViewManagement;
using Windows.UI.WindowManagement;
Expand All @@ -18,6 +19,8 @@ public static class ThemeHelper
{
private static Window CurrentApplicationWindow;

public static bool IsStatusBarSupported { get; } = ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar");

// Keep reference so it does not get optimized/garbage collected
public static UISettings UISettings { get; } = new UISettings();
public static AccessibilitySettings AccessibilitySettings { get; } = new AccessibilitySettings();
Expand Down Expand Up @@ -166,7 +169,7 @@ public static async void UpdateSystemCaptionButtonColors()
{
await window.Dispatcher.ResumeForegroundAsync();
if (UIHelper.HasStatusBar)
if (IsStatusBarSupported)
{
StatusBar StatusBar = StatusBar.GetForCurrentView();
StatusBar.ForegroundColor = ForegroundColor;
Expand Down Expand Up @@ -206,7 +209,7 @@ public static async void UpdateSystemCaptionButtonColors(Window window)
Color ForegroundColor = IsDark || IsHighContrast ? Colors.White : Colors.Black;
Color BackgroundColor = IsHighContrast ? Color.FromArgb(255, 0, 0, 0) : IsDark ? Color.FromArgb(255, 32, 32, 32) : Color.FromArgb(255, 243, 243, 243);

if (UIHelper.HasStatusBar)
if (IsStatusBarSupported)
{
StatusBar StatusBar = StatusBar.GetForCurrentView();
StatusBar.ForegroundColor = ForegroundColor;
Expand Down
9 changes: 2 additions & 7 deletions MicaDemo/Helpers/UIHelper.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using Windows.ApplicationModel.Core;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using Windows.UI.Xaml;

namespace MicaDemo.Helpers
{
internal static class UIHelper
{
public static bool HasTitleBar => !CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar;
public static bool HasStatusBar { get; } = ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar");

public static double TitleBarHeight => HasStatusBar ? 4 : 32;
public static double TitleBarHeight { get; } = ThemeHelper.IsStatusBarSupported ? 4 : 32;
public static Thickness ScrollViewerMargin => new Thickness(0, TitleBarHeight, 0, TitleBarHeight);
}
}
14 changes: 9 additions & 5 deletions MicaForUWP/MicaForUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<LangVersion>7.3</LangVersion>
<TargetFrameworks>uap10.0</TargetFrameworks>
<TargetFrameworks Condition="'$(FullTargets)' == 'true'">$(TargetFrameworks);native;netcoreapp3.1;uap10.0.15138.0</TargetFrameworks>
<TargetFrameworks Condition="'$(AddCSWinRT)' == 'true'">$(TargetFrameworks);net6.0-windows10.0.22000.0</TargetFrameworks>
<TargetFrameworks Condition="'$(AddCSWinRT)' == 'true'">$(TargetFrameworks);net8.0-windows10.0.22000.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -46,10 +46,14 @@
<NuspecProperties>id=$(AssemblyName);version=$(VersionPrefix);title=$(Title);authors=$(Authors);requireLicenseAcceptance=$(PackageRequireLicenseAcceptance);license=$(PackageLicenseExpression);icon=$(PackageIcon);readme=$(PackageReadmeFile);projectUrl=$(PackageProjectUrl);iconUrl=$(PackageIconUrl);description=$(Description);releaseNotes=$(PackageReleaseNotes);copyright=$(Copyright);repositoryType=$(RepositoryType);repositoryUrl=$(PackageProjectUrl);repositoryCommit=$(RepositoryCommit);buildOutput=bin\$(Configuration)</NuspecProperties>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0-windows10.0.17763.0'))">
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0-windows10.0.22000.0'))">
<CsWinRTIncludes>Microsoft.Graphics.Canvas</CsWinRTIncludes>
<LangVersion>latest</LangVersion>
<WindowsSdkPackageVersion>10.0.22000.37-preview</WindowsSdkPackageVersion>
<WindowsSdkPackageVersion>10.0.22000.42</WindowsSdkPackageVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -64,8 +68,8 @@
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.26100.1" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0-windows10.0.17763.0'))">
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240722.1" />
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0-windows10.0.17763.0'))">
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.1" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0'">
Expand Down

0 comments on commit 87feae3

Please sign in to comment.