Refactor
This commit is contained in:
parent
1e4c489983
commit
8dd59cb08a
147 changed files with 259 additions and 269 deletions
28
Source/LibationAvalonia/AvaloniaUtils.cs
Normal file
28
Source/LibationAvalonia/AvaloniaUtils.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Avalonia.Media;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationAvalonia
|
||||
{
|
||||
internal static class AvaloniaUtils
|
||||
{
|
||||
public static IBrush GetBrushFromResources(string name)
|
||||
=> GetBrushFromResources(name, Brushes.Transparent);
|
||||
public static IBrush GetBrushFromResources(string name, IBrush defaultBrush)
|
||||
{
|
||||
if (App.Current.Styles.TryGetResource(name, out var value) && value is IBrush brush)
|
||||
return brush;
|
||||
return defaultBrush;
|
||||
}
|
||||
|
||||
public static T ShowDialogSynchronously<T>(this Avalonia.Controls.Window window, Avalonia.Controls.Window owner)
|
||||
{
|
||||
using var source = new CancellationTokenSource();
|
||||
var dialogTask = window.ShowDialog<T>(owner);
|
||||
dialogTask.ContinueWith(t => source.Cancel(), TaskScheduler.FromCurrentSynchronizationContext());
|
||||
Avalonia.Threading.Dispatcher.UIThread.MainLoop(source.Token);
|
||||
return dialogTask.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue