update style.

This commit is contained in:
Dong Bin
2025-01-18 02:02:42 +08:00
parent 2ab46bd77e
commit d63a0f6bea
3 changed files with 90 additions and 68 deletions

View File

@@ -5,19 +5,17 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Logging;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using Irihi.Avalonia.Shared.Common;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
[TemplatePart(Name = "PART_Button", Type = typeof(Button))]
[TemplatePart(Name = PART_Button, Type = typeof(Button))]
public class PathPicker : TemplatedControl
{
public const string PART_Button = "PART_Button";
public static readonly StyledProperty<string> SuggestedStartPathProperty =
AvaloniaProperty.Register<PathPicker, string>(
nameof(SuggestedStartPath), string.Empty);
@@ -185,7 +183,7 @@ public class PathPicker : TemplatedControl
{
base.OnApplyTemplate(e);
Button.ClickEvent.RemoveHandler(LaunchPicker, _button);
_button = e.NameScope.Find<Button>("PART_Button");
_button = e.NameScope.Find<Button>(PART_Button);
Button.ClickEvent.AddHandler(LaunchPicker, _button);
}
@@ -243,7 +241,7 @@ public class PathPicker : TemplatedControl
try
{
if (TopLevel.GetTopLevel(this)?.StorageProvider is not { } storageProvider) return;
_button?.SetValue(IsEnabledProperty, false);
switch (UsePickerType)
{
case UsePickerTypes.OpenFile:
@@ -273,7 +271,7 @@ public class PathPicker : TemplatedControl
?.TryGetLocalPath();
UpdateSelectedPaths(string.IsNullOrEmpty(path)
? Array.Empty<string>()
: [path!]);
: [path]);
break;
case UsePickerTypes.OpenFolder:
FolderPickerOpenOptions folderPickerOpenOptions = new()
@@ -298,8 +296,10 @@ public class PathPicker : TemplatedControl
{
Logger.TryGet(LogEventLevel.Error, LogArea.Control)?.Log(this, $"{exception}");
}
return;
finally
{
_button?.SetValue(IsEnabledProperty, true);
}
}
private void UpdateSelectedPaths(IReadOnlyList<string> newList)