mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Create a shared project with all Win App common files (8.1 and 10)
Finally use the dependency injected Resource Service
This commit is contained in:
18
WinAppCommon/Extensions/ColorExtensions.cs
Normal file
18
WinAppCommon/Extensions/ColorExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Drawing;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
namespace ModernKeePass.Extensions
|
||||
{
|
||||
public static class ColorExtensions
|
||||
{
|
||||
public static Color ToColor(this SolidColorBrush brush)
|
||||
{
|
||||
return Color.FromArgb(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B);
|
||||
}
|
||||
|
||||
public static SolidColorBrush ToSolidColorBrush(this Color color)
|
||||
{
|
||||
return new SolidColorBrush(Windows.UI.Color.FromArgb(color.A, color.R, color.G, color.B));
|
||||
}
|
||||
}
|
||||
}
|
32
WinAppCommon/Extensions/DispatcherTaskExtensions.cs
Normal file
32
WinAppCommon/Extensions/DispatcherTaskExtensions.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace ModernKeePass.Extensions
|
||||
{
|
||||
public static class DispatcherTaskExtensions
|
||||
{
|
||||
public static async Task<T> RunTaskAsync<T>(this CoreDispatcher dispatcher,
|
||||
Func<Task<T>> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
await dispatcher.RunAsync(priority, async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
taskCompletionSource.SetResult(await func());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
taskCompletionSource.SetException(ex);
|
||||
}
|
||||
});
|
||||
return await taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
// There is no TaskCompletionSource<void> so we use a bool that we throw away.
|
||||
public static async Task RunTaskAsync(this CoreDispatcher dispatcher,
|
||||
Func<Task> func, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal) =>
|
||||
await RunTaskAsync(dispatcher, async () => { await func(); return false; }, priority);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user