fix:should be PathPickerForListView in demo

add:Maybe we can add a command demo here to show how to trigger the bound command.
change:I think these two themes should be merged, and the "AcceptReturn" should just be controlled by "AllowMultiple"
add:One more thing, we should add a property to control what to do when user cancelled a selection. Sometimes I just want to keep the original selection.
This commit is contained in:
望尘空忧
2025-01-13 19:08:55 +08:00
parent c6bbcf7226
commit d3aa632d1d
4 changed files with 54 additions and 39 deletions

View File

@@ -54,6 +54,16 @@ public class PathPicker : TemplatedControl
AvaloniaProperty.Register<PathPicker, string?>(
nameof(SelectedPathsText), defaultBindingMode: BindingMode.TwoWay);
public static readonly StyledProperty<bool> IsCancelingPickerAlsoTriggersProperty =
AvaloniaProperty.Register<PathPicker, bool>(
nameof(IsCancelingPickerAlsoTriggers));
public bool IsCancelingPickerAlsoTriggers
{
get => GetValue(IsCancelingPickerAlsoTriggersProperty);
set => SetValue(IsCancelingPickerAlsoTriggersProperty, value);
}
public string? SelectedPathsText
{
get => GetValue(SelectedPathsTextProperty);
@@ -129,7 +139,7 @@ public class PathPicker : TemplatedControl
{
_twoConvertLock = true;
var stringBuilder = new StringBuilder();
stringBuilder.Append(SelectedPaths.FirstOrDefault());
stringBuilder.Append(SelectedPaths[0]);
foreach (var item in SelectedPaths.Skip(1))
{
stringBuilder.AppendLine(item);
@@ -268,7 +278,7 @@ public class PathPicker : TemplatedControl
throw new ArgumentOutOfRangeException();
}
if (SelectedPaths.Count != 0)
if (SelectedPaths.Count != 0 || IsCancelingPickerAlsoTriggers)
Command?.Execute(SelectedPaths);
}
catch (Exception exception)