From d3aa632d1dc3f47824ab0d5feafdab3ff23d6a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9B=E5=B0=98=E7=A9=BA=E5=BF=A7?= Date: Mon, 13 Jan 2025 19:08:55 +0800 Subject: [PATCH] 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. --- demo/Ursa.Demo/Pages/PathPickerDemo.axaml | 32 +++++++-------- .../ViewModels/PathPickerDemoViewModel.cs | 8 ++++ .../Controls/PathPicker.axaml | 39 +++++++++---------- src/Ursa/Controls/PathPicker/PathPicker.cs | 14 ++++++- 4 files changed, 54 insertions(+), 39 deletions(-) diff --git a/demo/Ursa.Demo/Pages/PathPickerDemo.axaml b/demo/Ursa.Demo/Pages/PathPickerDemo.axaml index 933a7b3..8ffe642 100644 --- a/demo/Ursa.Demo/Pages/PathPickerDemo.axaml +++ b/demo/Ursa.Demo/Pages/PathPickerDemo.axaml @@ -32,6 +32,10 @@ + + @@ -47,20 +51,9 @@ AllowMultiple="{Binding #AllowMultiple.IsChecked}" UsePickerType="{Binding #UsePickerType.Value}" SelectedPathsText="{Binding Path,Mode=OneWayToSource}" - SelectedPaths="{Binding Paths,Mode=OneWayToSource}"> - - - - + SelectedPaths="{Binding Paths,Mode=OneWayToSource}" + Command="{Binding SelectedCommand}" + IsCancelingPickerAlsoTriggers="{Binding #IsCancelingPickerAlsoTriggers.IsChecked}"> @@ -73,11 +66,13 @@ AllowMultiple="{Binding #AllowMultiple.IsChecked}" UsePickerType="{Binding #UsePickerType.Value}" SelectedPathsText="{Binding Path,Mode=OneWayToSource}" - SelectedPaths="{Binding Paths,Mode=OneWayToSource}"> + SelectedPaths="{Binding Paths,Mode=OneWayToSource}" + Command="{Binding SelectedCommand}" + IsCancelingPickerAlsoTriggers="{Binding #IsCancelingPickerAlsoTriggers.IsChecked}"> - + SelectedPaths="{Binding Paths,Mode=OneWayToSource}" + Command="{Binding SelectedCommand}" + IsCancelingPickerAlsoTriggers="{Binding #IsCancelingPickerAlsoTriggers.IsChecked}"> + diff --git a/demo/Ursa.Demo/ViewModels/PathPickerDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/PathPickerDemoViewModel.cs index 307556d..6bb9d2a 100644 --- a/demo/Ursa.Demo/ViewModels/PathPickerDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/PathPickerDemoViewModel.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; namespace Ursa.Demo.ViewModels; @@ -7,4 +8,11 @@ public partial class PathPickerDemoViewModel : ViewModelBase { [ObservableProperty] private string? _path; [ObservableProperty] private IReadOnlyList? _paths; + [ObservableProperty] private int _commandTriggerCount = 0; + + [RelayCommand] + private void Selected(IReadOnlyList paths) + { + CommandTriggerCount++; + } } \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/PathPicker.axaml b/src/Ursa.Themes.Semi/Controls/PathPicker.axaml index 5ff8c86..cc0ec95 100644 --- a/src/Ursa.Themes.Semi/Controls/PathPicker.axaml +++ b/src/Ursa.Themes.Semi/Controls/PathPicker.axaml @@ -11,32 +11,31 @@ Content="{TemplateBinding Title}" Margin="1,0,0,0"> - - - - - - - - - - - - + + + + + + diff --git a/src/Ursa/Controls/PathPicker/PathPicker.cs b/src/Ursa/Controls/PathPicker/PathPicker.cs index 992c6b7..647147c 100644 --- a/src/Ursa/Controls/PathPicker/PathPicker.cs +++ b/src/Ursa/Controls/PathPicker/PathPicker.cs @@ -54,6 +54,16 @@ public class PathPicker : TemplatedControl AvaloniaProperty.Register( nameof(SelectedPathsText), defaultBindingMode: BindingMode.TwoWay); + public static readonly StyledProperty IsCancelingPickerAlsoTriggersProperty = + AvaloniaProperty.Register( + 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)