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

@@ -16,7 +16,7 @@
Content="PathPicker aggregates a file selector and provides a Command property. The Command is triggered solely after opening the file selector and selecting a file, whereupon the Command receives an IReadOnlyList<string> parameter."> Content="PathPicker aggregates a file selector and provides a Command property. The Command is triggered solely after opening the file selector and selecting a file, whereupon the Command receives an IReadOnlyList<string> parameter.">
</HeaderedContentControl> </HeaderedContentControl>
<u:Form LabelAlignment="Left" LabelPosition="Left" LabelWidth="*" HorizontalAlignment="Stretch"> <u:Form LabelAlignment="Left" LabelPosition="Left" LabelWidth="*" HorizontalAlignment="Stretch">
<TextBox Name="Title" u:FormItem.Label="Title"></TextBox> <TextBox Name="Title" u:FormItem.Label="Title" Text="选择文件"></TextBox>
<TextBox Name="SuggestedFileName" u:FormItem.Label="SuggestedFileName" <TextBox Name="SuggestedFileName" u:FormItem.Label="SuggestedFileName"
Watermark="filename(not have file extension)"> Watermark="filename(not have file extension)">
</TextBox> </TextBox>
@@ -29,18 +29,19 @@
<TextBox Name="DefaultFileExtension" u:FormItem.Label="DefaultFileExtension" <TextBox Name="DefaultFileExtension" u:FormItem.Label="DefaultFileExtension"
Watermark="json"> Watermark="json">
</TextBox> </TextBox>
<ToggleButton Name="AllowMultiple" Content="AllowMultiple" u:FormItem.NoLabel="True" <CheckBox Name="AllowMultiple" Content="AllowMultiple" u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch"> >
</ToggleButton> </CheckBox>
<ToggleButton Name="IsOmitCommandOnCancel" Content="Do not trigger the command after unselecting." <CheckBox Name="IsOmitCommandOnCancel" Content="Do not trigger the command after unselecting."
u:FormItem.NoLabel="True" u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch"> >
</ToggleButton> </CheckBox>
<ToggleButton Name="IsClearSelectionOnCancel" Content="Clear the selection when unselecting." <CheckBox Name="IsClearSelectionOnCancel" Content="Clear the selection when unselecting."
u:FormItem.NoLabel="True" u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch"> >
</ToggleButton> </CheckBox>
<u:EnumSelector Name="UsePickerType" EnumType="u:UsePickerTypes" u:FormItem.Label="UsePickerType"></u:EnumSelector> <u:EnumSelector Name="UsePickerType" EnumType="u:UsePickerTypes" u:FormItem.Label="UsePickerType"></u:EnumSelector>
<u:ControlClassesInput Name="ClassInput" u:FormItem.Label="Style Class" HorizontalAlignment="Left"></u:ControlClassesInput>
</u:Form> </u:Form>
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
@@ -48,11 +49,12 @@
<StackPanel Spacing="2"> <StackPanel Spacing="2">
<HeaderedContentControl Header="Default"> <HeaderedContentControl Header="Default">
<u:PathPicker Title="{Binding #Title.Text}" <u:PathPicker Title="{Binding #Title.Text}"
u:ControlClassesInput.Source="{Binding #ClassInput}"
SuggestedFileName="{Binding #SuggestedFileName.Text}" SuggestedFileName="{Binding #SuggestedFileName.Text}"
SuggestedStartPath="{Binding #SuggestedStartPath.Text}" SuggestedStartPath="{Binding #SuggestedStartPath.Text}"
FileFilter="{Binding #FileFilter.Text}" FileFilter="{Binding #FileFilter.Text}"
DefaultFileExtension="{Binding #DefaultFileExtension.Text}" DefaultFileExtension="{Binding #DefaultFileExtension.Text}"
AllowMultiple="{Binding #AllowMultiple.IsChecked}" AllowMultiple="{Binding #AllowMultiple.IsChecked, Mode=TwoWay}"
UsePickerType="{Binding #UsePickerType.Value}" UsePickerType="{Binding #UsePickerType.Value}"
SelectedPathsText="{Binding Path,Mode=OneWayToSource}" SelectedPathsText="{Binding Path,Mode=OneWayToSource}"
SelectedPaths="{Binding Paths,Mode=OneWayToSource}" SelectedPaths="{Binding Paths,Mode=OneWayToSource}"
@@ -61,8 +63,8 @@
IsClearSelectionOnCancel="{Binding #IsClearSelectionOnCancel.IsChecked}"> IsClearSelectionOnCancel="{Binding #IsClearSelectionOnCancel.IsChecked}">
</u:PathPicker> </u:PathPicker>
</HeaderedContentControl> </HeaderedContentControl>
<HeaderedContentControl Header="PathPickerOnlyButton"> <HeaderedContentControl Header="ButtonPathPicker">
<u:PathPicker Theme="{DynamicResource PathPickerOnlyButton}" <u:PathPicker Theme="{DynamicResource ButtonPathPicker}"
Title="{Binding #Title.Text}" Title="{Binding #Title.Text}"
SuggestedFileName="{Binding #SuggestedFileName.Text}" SuggestedFileName="{Binding #SuggestedFileName.Text}"
SuggestedStartPath="{Binding #SuggestedStartPath.Text}" SuggestedStartPath="{Binding #SuggestedStartPath.Text}"

View File

@@ -1,81 +1,101 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" <ResourceDictionary
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="https://github.com/avaloniaui"
xmlns:ursa="https://irihi.tech/ursa"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<ControlTheme x:Key="{x:Type ursa:PathPicker}" TargetType="ursa:PathPicker"> xmlns:converters="clr-namespace:Ursa.Themes.Semi.Converters"
xmlns:u="https://irihi.tech/ursa">
<Design.PreviewWith>
<StackPanel Margin="20">
<u:PathPicker Title="Hello World" Width="300" />
</StackPanel>
</Design.PreviewWith>
<ControlTheme x:Key="{x:Type u:PathPicker}" TargetType="u:PathPicker">
<Setter Property="CornerRadius" Value="3" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<DockPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" <DockPanel>
VerticalAlignment="{TemplateBinding VerticalAlignment}"> <Button
<Button Name="PART_Button" Name="{x:Static u:PathPicker.PART_Button}"
DockPanel.Dock="Right" Content="{TemplateBinding Title}"
Content="{TemplateBinding Title}" HorizontalAlignment="Stretch"
Margin="1,0,0,0"> VerticalAlignment="Center"
</Button> DockPanel.Dock="Right" />
<TextBox Name="PART_TextBox" <TextBox
DockPanel.Dock="Left" Name="PART_TextBox"
AcceptsReturn="{TemplateBinding AllowMultiple}" AcceptsReturn="{TemplateBinding AllowMultiple}"
Text="{TemplateBinding SelectedPathsText,Mode=TwoWay}"> DockPanel.Dock="Left"
</TextBox> Text="{TemplateBinding SelectedPathsText, Mode=TwoWay}" />
</DockPanel> </DockPanel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^[AllowMultiple=False]"> <Style Selector="^ /template/ Button#PART_Button:pressed">
<Style Selector="^ /template/ Button#PART_Button"> <Setter Property="RenderTransform" Value="{x:Null}" />
<Setter Property="DockPanel.Dock" Value="Right"></Setter>
</Style>
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="DockPanel.Dock" Value="Left"></Setter>
</Style>
</Style> </Style>
<Style Selector="^[AllowMultiple=True]">
<Style Selector="^ /template/ Button#PART_Button">
<Setter Property="DockPanel.Dock" Value="Right" />
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="CornerRadius" Value="{TemplateBinding CornerRadius, Converter={x:Static converters:CornerRadiusTakeConverter.Right}}" />
<Setter Property="Margin" Value="1 0 0 0"></Setter>
</Style>
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="DockPanel.Dock" Value="Left" />
<Setter Property="CornerRadius" Value="{TemplateBinding CornerRadius, Converter={x:Static converters:CornerRadiusTakeConverter.Left}}" />
</Style>
<Style Selector="^.Top">
<Style Selector="^ /template/ Button#PART_Button"> <Style Selector="^ /template/ Button#PART_Button">
<Setter Property="DockPanel.Dock" Value="Top"></Setter> <Setter Property="DockPanel.Dock" Value="Top" />
<Setter Property="CornerRadius" Value="{TemplateBinding CornerRadius, Converter={x:Static converters:CornerRadiusTakeConverter.Top}}" />
<Setter Property="Margin" Value="0 0 0 1"></Setter>
</Style> </Style>
<Style Selector="^ /template/ TextBox#PART_TextBox"> <Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="DockPanel.Dock" Value="Bottom"></Setter> <Setter Property="DockPanel.Dock" Value="Bottom" />
<Setter Property="CornerRadius" Value="{TemplateBinding CornerRadius, Converter={x:Static converters:CornerRadiusTakeConverter.Bottom}}" />
</Style> </Style>
</Style> </Style>
</ControlTheme> </ControlTheme>
<ControlTheme x:Key="PathPickerOnlyButton" TargetType="ursa:PathPicker"> <ControlTheme x:Key="ButtonPathPicker" TargetType="u:PathPicker">
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Button Name="PART_Button" <Button
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Name="{x:Static u:PathPicker.PART_Button}"
VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Content="{TemplateBinding Title}"> VerticalAlignment="{TemplateBinding VerticalAlignment}"
</Button> Content="{TemplateBinding Title}" />
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^ /template/ Button#PART_Button:pressed">
<Setter Property="RenderTransform" Value="{x:Null}" />
</Style>
</ControlTheme> </ControlTheme>
<ControlTheme x:Key="PathPickerForListView" TargetType="ursa:PathPicker"> <ControlTheme x:Key="PathPickerForListView" TargetType="u:PathPicker">
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Expander HorizontalAlignment="{TemplateBinding HorizontalAlignment}" <Expander HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Expander.Header> <Expander.Header>
<Button Name="PART_Button" <Button
HorizontalAlignment="Stretch" Name="PART_Button"
Content="{TemplateBinding Title}"> HorizontalAlignment="Stretch"
Content="{TemplateBinding Title}">
<Button.Theme> <Button.Theme>
<ControlTheme TargetType="Button"> <ControlTheme TargetType="Button">
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<TextPresenter Text="{TemplateBinding Content}" <TextPresenter
Background="Transparent" HorizontalAlignment="Stretch"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalAlignment="Stretch"> Background="Transparent"
</TextPresenter> Text="{TemplateBinding Content}" />
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</ControlTheme> </ControlTheme>
</Button.Theme> </Button.Theme>
</Button> </Button>
</Expander.Header> </Expander.Header>
<ListBox ItemsSource="{TemplateBinding SelectedPaths}"></ListBox> <ListBox ItemsSource="{TemplateBinding SelectedPaths}" />
</Expander> </Expander>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

View File

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