update style.
This commit is contained in:
@@ -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.">
|
||||
</HeaderedContentControl>
|
||||
<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"
|
||||
Watermark="filename(not have file extension)">
|
||||
</TextBox>
|
||||
@@ -29,18 +29,19 @@
|
||||
<TextBox Name="DefaultFileExtension" u:FormItem.Label="DefaultFileExtension"
|
||||
Watermark="json">
|
||||
</TextBox>
|
||||
<ToggleButton Name="AllowMultiple" Content="AllowMultiple" u:FormItem.NoLabel="True"
|
||||
HorizontalAlignment="Stretch">
|
||||
</ToggleButton>
|
||||
<ToggleButton Name="IsOmitCommandOnCancel" Content="Do not trigger the command after unselecting."
|
||||
u:FormItem.NoLabel="True"
|
||||
HorizontalAlignment="Stretch">
|
||||
</ToggleButton>
|
||||
<ToggleButton Name="IsClearSelectionOnCancel" Content="Clear the selection when unselecting."
|
||||
u:FormItem.NoLabel="True"
|
||||
HorizontalAlignment="Stretch">
|
||||
</ToggleButton>
|
||||
<CheckBox Name="AllowMultiple" Content="AllowMultiple" u:FormItem.NoLabel="True"
|
||||
>
|
||||
</CheckBox>
|
||||
<CheckBox Name="IsOmitCommandOnCancel" Content="Do not trigger the command after unselecting."
|
||||
u:FormItem.NoLabel="True"
|
||||
>
|
||||
</CheckBox>
|
||||
<CheckBox Name="IsClearSelectionOnCancel" Content="Clear the selection when unselecting."
|
||||
u:FormItem.NoLabel="True"
|
||||
>
|
||||
</CheckBox>
|
||||
<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>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
@@ -48,11 +49,12 @@
|
||||
<StackPanel Spacing="2">
|
||||
<HeaderedContentControl Header="Default">
|
||||
<u:PathPicker Title="{Binding #Title.Text}"
|
||||
u:ControlClassesInput.Source="{Binding #ClassInput}"
|
||||
SuggestedFileName="{Binding #SuggestedFileName.Text}"
|
||||
SuggestedStartPath="{Binding #SuggestedStartPath.Text}"
|
||||
FileFilter="{Binding #FileFilter.Text}"
|
||||
DefaultFileExtension="{Binding #DefaultFileExtension.Text}"
|
||||
AllowMultiple="{Binding #AllowMultiple.IsChecked}"
|
||||
AllowMultiple="{Binding #AllowMultiple.IsChecked, Mode=TwoWay}"
|
||||
UsePickerType="{Binding #UsePickerType.Value}"
|
||||
SelectedPathsText="{Binding Path,Mode=OneWayToSource}"
|
||||
SelectedPaths="{Binding Paths,Mode=OneWayToSource}"
|
||||
@@ -61,8 +63,8 @@
|
||||
IsClearSelectionOnCancel="{Binding #IsClearSelectionOnCancel.IsChecked}">
|
||||
</u:PathPicker>
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Header="PathPickerOnlyButton">
|
||||
<u:PathPicker Theme="{DynamicResource PathPickerOnlyButton}"
|
||||
<HeaderedContentControl Header="ButtonPathPicker">
|
||||
<u:PathPicker Theme="{DynamicResource ButtonPathPicker}"
|
||||
Title="{Binding #Title.Text}"
|
||||
SuggestedFileName="{Binding #SuggestedFileName.Text}"
|
||||
SuggestedStartPath="{Binding #SuggestedStartPath.Text}"
|
||||
|
||||
@@ -1,81 +1,101 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ursa="https://irihi.tech/ursa">
|
||||
<ControlTheme x:Key="{x:Type ursa:PathPicker}" TargetType="ursa:PathPicker">
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
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">
|
||||
<ControlTemplate>
|
||||
<DockPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}">
|
||||
<Button Name="PART_Button"
|
||||
DockPanel.Dock="Right"
|
||||
Content="{TemplateBinding Title}"
|
||||
Margin="1,0,0,0">
|
||||
</Button>
|
||||
<TextBox Name="PART_TextBox"
|
||||
DockPanel.Dock="Left"
|
||||
AcceptsReturn="{TemplateBinding AllowMultiple}"
|
||||
Text="{TemplateBinding SelectedPathsText,Mode=TwoWay}">
|
||||
</TextBox>
|
||||
<DockPanel>
|
||||
<Button
|
||||
Name="{x:Static u:PathPicker.PART_Button}"
|
||||
Content="{TemplateBinding Title}"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Right" />
|
||||
<TextBox
|
||||
Name="PART_TextBox"
|
||||
AcceptsReturn="{TemplateBinding AllowMultiple}"
|
||||
DockPanel.Dock="Left"
|
||||
Text="{TemplateBinding SelectedPathsText, Mode=TwoWay}" />
|
||||
</DockPanel>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
<Style Selector="^[AllowMultiple=False]">
|
||||
<Style Selector="^ /template/ Button#PART_Button">
|
||||
<Setter Property="DockPanel.Dock" Value="Right"></Setter>
|
||||
</Style>
|
||||
<Style Selector="^ /template/ TextBox#PART_TextBox">
|
||||
<Setter Property="DockPanel.Dock" Value="Left"></Setter>
|
||||
</Style>
|
||||
<Style Selector="^ /template/ Button#PART_Button:pressed">
|
||||
<Setter Property="RenderTransform" Value="{x:Null}" />
|
||||
</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">
|
||||
<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 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>
|
||||
</ControlTheme>
|
||||
|
||||
|
||||
<ControlTheme x:Key="PathPickerOnlyButton" TargetType="ursa:PathPicker">
|
||||
<ControlTheme x:Key="ButtonPathPicker" TargetType="u:PathPicker">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Button Name="PART_Button"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
Content="{TemplateBinding Title}">
|
||||
</Button>
|
||||
<Button
|
||||
Name="{x:Static u:PathPicker.PART_Button}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
Content="{TemplateBinding Title}" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ Button#PART_Button:pressed">
|
||||
<Setter Property="RenderTransform" Value="{x:Null}" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
|
||||
<ControlTheme x:Key="PathPickerForListView" TargetType="ursa:PathPicker">
|
||||
<ControlTheme x:Key="PathPickerForListView" TargetType="u:PathPicker">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Expander HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}">
|
||||
<Expander HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
|
||||
<Expander.Header>
|
||||
<Button Name="PART_Button"
|
||||
HorizontalAlignment="Stretch"
|
||||
Content="{TemplateBinding Title}">
|
||||
<Button
|
||||
Name="PART_Button"
|
||||
HorizontalAlignment="Stretch"
|
||||
Content="{TemplateBinding Title}">
|
||||
<Button.Theme>
|
||||
<ControlTheme TargetType="Button">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<TextPresenter Text="{TemplateBinding Content}"
|
||||
Background="Transparent"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
</TextPresenter>
|
||||
<TextPresenter
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="Transparent"
|
||||
Text="{TemplateBinding Content}" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</Button.Theme>
|
||||
</Button>
|
||||
</Expander.Header>
|
||||
<ListBox ItemsSource="{TemplateBinding SelectedPaths}"></ListBox>
|
||||
<ListBox ItemsSource="{TemplateBinding SelectedPaths}" />
|
||||
</Expander>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user