commit
ecde71c999
@ -6,35 +6,56 @@
|
||||
xmlns:controls="using:Avalonia.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignHeight="1450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel Spacing="20">
|
||||
<StackPanel
|
||||
VerticalAlignment="Top"
|
||||
Orientation="Horizontal"
|
||||
Spacing="20">
|
||||
<ColorView ColorSpectrumShape="Ring" />
|
||||
<ColorView ColorSpectrumShape="Box" />
|
||||
<ColorView Palette="{DynamicResource SemiColorPalette}" />
|
||||
<ScrollViewer>
|
||||
<StackPanel Spacing="20">
|
||||
<StackPanel
|
||||
VerticalAlignment="Top"
|
||||
Orientation="Horizontal"
|
||||
Spacing="20">
|
||||
<ColorView Name="Test" ColorSpectrumShape="Ring" />
|
||||
<ColorView ColorSpectrumShape="Box" />
|
||||
<ColorView Palette="{DynamicResource SemiColorPalette}" />
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
VerticalAlignment="Top"
|
||||
Orientation="Horizontal">
|
||||
<ColorView
|
||||
Name="SimpleColorViewTest"
|
||||
Theme="{StaticResource SimpleColorView}"
|
||||
IsAlphaVisible="True"
|
||||
HsvColor="hsv(120,11%,10%)" />
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding #SimpleColorViewTest.HsvColor}" />
|
||||
<TextBlock Text="{Binding #SimpleColorViewTest.Color}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
<ColorPicker ColorSpectrumShape="Ring">
|
||||
<ColorPicker.Palette>
|
||||
<controls:FlatHalfColorPalette />
|
||||
</ColorPicker.Palette>
|
||||
</ColorPicker>
|
||||
<ColorPicker ColorSpectrumShape="Box">
|
||||
<ColorPicker.Palette>
|
||||
<colorPicker:SemiColorLightPalette />
|
||||
</ColorPicker.Palette>
|
||||
</ColorPicker>
|
||||
|
||||
<ColorPicker ColorSpectrumShape="Box" Theme="{DynamicResource HexColorPicker}">
|
||||
<ColorPicker.Palette>
|
||||
<colorPicker:SemiColorLightPalette />
|
||||
</ColorPicker.Palette>
|
||||
</ColorPicker>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
<ColorPicker Theme="{StaticResource SimpleColorPicker}"
|
||||
HsvColor="hsv(120,11%,10%)" />
|
||||
<ColorPicker Theme="{StaticResource HexSimpleColorPicker}"
|
||||
HsvColor="hsv(120,11%,10%)" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
<ColorPicker ColorSpectrumShape="Ring">
|
||||
<ColorPicker.Palette>
|
||||
<controls:FlatHalfColorPalette />
|
||||
</ColorPicker.Palette>
|
||||
</ColorPicker>
|
||||
<ColorPicker ColorSpectrumShape="Box">
|
||||
<ColorPicker.Palette>
|
||||
<colorPicker:SemiColorLightPalette />
|
||||
</ColorPicker.Palette>
|
||||
</ColorPicker>
|
||||
|
||||
<ColorPicker ColorSpectrumShape="Box" Theme="{DynamicResource HexColorPicker}">
|
||||
<ColorPicker.Palette>
|
||||
<colorPicker:SemiColorLightPalette />
|
||||
</ColorPicker.Palette>
|
||||
</ColorPicker>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
@ -234,7 +234,7 @@
|
||||
RowDefinitions="Auto,24,1*,1*,1*,1*,12"
|
||||
Tag="{TemplateBinding ColorModel}">
|
||||
<Grid.Styles>
|
||||
<Style Selector="NumericUpDown /template/ TextBox">
|
||||
<Style Selector="NumericUpDown">
|
||||
<Setter Property="InnerLeftContent">
|
||||
<Template>
|
||||
<TextBlock Width="12" Text="{Binding $parent[NumericUpDown].Tag}" />
|
||||
@ -514,4 +514,199 @@
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
|
||||
<ControlTheme
|
||||
x:Key="SimpleColorPicker"
|
||||
BasedOn="{StaticResource {x:Type ColorPicker}}"
|
||||
TargetType="ColorPicker">
|
||||
<Setter Property="ColorSpectrumComponents" Value="SaturationValue" />
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="{x:Type ColorPicker}">
|
||||
<DropDownButton
|
||||
Width="{TemplateBinding Width}"
|
||||
Height="{TemplateBinding Height}"
|
||||
Padding="0,0,10,0"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"
|
||||
ClipToBounds="True"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
UseLayoutRounding="False">
|
||||
<DropDownButton.Styles>
|
||||
<Style Selector="FlyoutPresenter.nopadding">
|
||||
<Setter Property="Padding" Value="0" />
|
||||
</Style>
|
||||
</DropDownButton.Styles>
|
||||
<DropDownButton.Flyout>
|
||||
<Flyout FlyoutPresenterClasses="nopadding" Placement="{DynamicResource SimpleColorPickerFlyoutPlacement}">
|
||||
|
||||
<!--
|
||||
The following is copy-pasted from the ColorView's control template.
|
||||
It MUST always be kept in sync with the ColorView (which is master).
|
||||
Note the only changes are resources specific to the ColorPicker.
|
||||
-->
|
||||
<Grid Width="280">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" MinHeight="280" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<!-- Spectrum Tab -->
|
||||
<Border
|
||||
Grid.Row="0"
|
||||
CornerRadius="8 8 0 0"
|
||||
ClipToBounds="True">
|
||||
<primitives:ColorSpectrum
|
||||
x:Name="ColorSpectrum"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Components="{TemplateBinding ColorSpectrumComponents}"
|
||||
HsvColor="{TemplateBinding HsvColor, Mode=TwoWay}"
|
||||
MaxHue="{TemplateBinding MaxHue}"
|
||||
MaxSaturation="{TemplateBinding MaxSaturation}"
|
||||
MaxValue="{TemplateBinding MaxValue}"
|
||||
MinHue="{TemplateBinding MinHue}"
|
||||
MinSaturation="{TemplateBinding MinSaturation}"
|
||||
MinValue="{TemplateBinding MinValue}"
|
||||
Shape="{TemplateBinding ColorSpectrumShape}" />
|
||||
</Border>
|
||||
<primitives:ColorSlider
|
||||
x:Name="ColorSpectrumThirdComponentSlider"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Third Component"
|
||||
ColorComponent="{Binding #ColorSpectrum.ThirdComponent}"
|
||||
ColorModel="Hsva"
|
||||
HsvColor="{TemplateBinding HsvColor, Mode=TwoWay}"
|
||||
IsVisible="{TemplateBinding IsColorSpectrumSliderVisible}"
|
||||
Orientation="Horizontal" />
|
||||
|
||||
<primitives:ColorSlider
|
||||
x:Name="ColorSpectrumAlphaSlider"
|
||||
Grid.Row="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Alpha Component"
|
||||
ColorComponent="Alpha"
|
||||
ColorModel="Hsva"
|
||||
HsvColor="{TemplateBinding HsvColor, Mode=TwoWay}"
|
||||
IsEnabled="{TemplateBinding IsAlphaEnabled}"
|
||||
IsVisible="{TemplateBinding IsAlphaVisible}"
|
||||
IsRoundingEnabled="True"
|
||||
IsSnapToTickEnabled="True"
|
||||
TickFrequency="1"
|
||||
Orientation="Horizontal">
|
||||
</primitives:ColorSlider>
|
||||
<StackPanel
|
||||
Grid.Row="3"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
Margin="0 8 0 0">
|
||||
<Border
|
||||
Background="{TemplateBinding Color, Converter={StaticResource ToBrushConverter}}"
|
||||
Width="20"
|
||||
Height="20"
|
||||
CornerRadius="4" />
|
||||
<Panel
|
||||
x:Name="PART_TextBoxPanel"
|
||||
Width="106"
|
||||
Margin="4 0 0 0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center">
|
||||
<TextBox
|
||||
x:Name="PART_HexTextBox"
|
||||
Classes="Small"
|
||||
InnerLeftContent="#"
|
||||
IsVisible="{Binding #ColorModelComboBox.SelectedValue, Converter={StaticResource ToColorModel}, ConverterParameter=Hex}"
|
||||
Text="{TemplateBinding Color, Converter={StaticResource ColorToHexConverter}, Mode=TwoWay}"
|
||||
MaxLength="8" />
|
||||
<TextBox
|
||||
x:Name="PART_RgbaTextBox"
|
||||
Classes="Small"
|
||||
IsVisible="{Binding #ColorModelComboBox.SelectedValue, Converter={StaticResource ToColorModel}, ConverterParameter=Rgba}"
|
||||
Text="{TemplateBinding Color, Converter={StaticResource ColorToTextConverter}, Mode=TwoWay}" />
|
||||
<TextBox
|
||||
x:Name="PART_HsvaTextBox"
|
||||
Classes="Small"
|
||||
IsVisible="{Binding #ColorModelComboBox.SelectedValue, Converter={StaticResource ToColorModel}, ConverterParameter=Hsva}"
|
||||
Text="{TemplateBinding HsvColor, Converter={StaticResource HsvColorToTextConverter}, Mode=TwoWay}" />
|
||||
</Panel>
|
||||
|
||||
<NumericUpDown
|
||||
x:Name="AlphaComponentNumericUpDown"
|
||||
Width="70"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
AllowSpin="True"
|
||||
Classes="Small"
|
||||
IsEnabled="{TemplateBinding IsAlphaEnabled}"
|
||||
Maximum="{Binding #ColorSpectrumAlphaSlider.Maximum}"
|
||||
Minimum="{Binding #ColorSpectrumAlphaSlider.Minimum}"
|
||||
NumberFormat="{StaticResource ColorViewComponentNumberFormat}"
|
||||
ShowButtonSpinner="False"
|
||||
InnerRightContent="%"
|
||||
IsVisible="{TemplateBinding IsAlphaVisible}"
|
||||
Value="{Binding #ColorSpectrumAlphaSlider.Value}" />
|
||||
<ComboBox
|
||||
x:Name="ColorModelComboBox"
|
||||
Width="80"
|
||||
VerticalAlignment="Center"
|
||||
Classes="Small"
|
||||
SelectedValue="Hex">
|
||||
Hex<ColorModel>Rgba</ColorModel>
|
||||
<ColorModel>Hsva</ColorModel>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Flyout>
|
||||
</DropDownButton.Flyout>
|
||||
</DropDownButton>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^[IsAlphaVisible=False] /template/ Panel#PART_TextBoxPanel">
|
||||
<Setter Property="Width" Value="176" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
|
||||
<ControlTheme
|
||||
x:Key="HexSimpleColorPicker"
|
||||
BasedOn="{StaticResource SimpleColorPicker}"
|
||||
TargetType="ColorPicker">
|
||||
<Setter Property="Width" Value="200" />
|
||||
<Setter Property="Content">
|
||||
<Template>
|
||||
<Grid ColumnDefinitions="Auto, *">
|
||||
<Border
|
||||
Grid.Column="0"
|
||||
Width="{Binding $self.Bounds.Height}"
|
||||
Margin="1,1,0,1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{DynamicResource ColorControlCheckeredBackgroundBrush}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}" />
|
||||
<Border
|
||||
Grid.Column="0"
|
||||
Width="{Binding $self.Bounds.Height}"
|
||||
Margin="1,1,0,1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{TemplateBinding HsvColor,
|
||||
Converter={StaticResource ToBrushConverter}}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}" />
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="Regular"
|
||||
Foreground="{DynamicResource TextBlockDefaultForeground}"
|
||||
Text="{Binding $parent[ColorPicker].Color}" />
|
||||
</Grid>
|
||||
</Template>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
@ -6,13 +6,17 @@
|
||||
xmlns:globalization="using:System.Globalization"
|
||||
xmlns:pc="using:Avalonia.Controls.Primitives.Converters"
|
||||
xmlns:primitives="using:Avalonia.Controls.Primitives"
|
||||
xmlns:cvts="clr-namespace:Semi.Avalonia.ColorPicker.Converters"
|
||||
x:CompileBindings="True">
|
||||
<!-- Add Resources Here -->
|
||||
<pc:ContrastBrushConverter x:Key="ContrastBrushConverter" />
|
||||
<converters:ColorToDisplayNameConverter x:Key="ColorToDisplayNameConverter" />
|
||||
<converters:ColorToHexConverter x:Key="ColorToHexConverter" />
|
||||
<converters:DoNothingForNullConverter x:Key="DoNothingForNullConverter" />
|
||||
<converters:EnumToBoolConverter x:Key="EnumToBoolConverter" />
|
||||
<converters:ToBrushConverter x:Key="ToBrushConverter" />
|
||||
<cvts:HsvColorToTextConverter x:Key="HsvColorToTextConverter" />
|
||||
<cvts:ColorToTextConverter x:Key="ColorToTextConverter" />
|
||||
<cvts:ToColorModel x:Key="ToColorModel" />
|
||||
<globalization:NumberFormatInfo x:Key="ColorViewComponentNumberFormat" NumberDecimalDigits="0" />
|
||||
|
||||
<VisualBrush
|
||||
@ -322,7 +326,7 @@
|
||||
RowDefinitions="Auto,24,1*,1*,1*,1*,12"
|
||||
UseLayoutRounding="False">
|
||||
<Grid.Styles>
|
||||
<Style Selector="NumericUpDown /template/ TextBox">
|
||||
<Style Selector="NumericUpDown">
|
||||
<Setter Property="InnerLeftContent">
|
||||
<Template>
|
||||
<TextBlock Width="12" Text="{Binding $parent[NumericUpDown].Tag}" />
|
||||
@ -376,7 +380,7 @@
|
||||
AutomationProperties.Name="Hexadecimal Color"
|
||||
InnerLeftContent="#"
|
||||
IsVisible="{TemplateBinding IsHexInputVisible}"
|
||||
MaxLength="9" />
|
||||
MaxLength="8" />
|
||||
</Grid>
|
||||
<!-- Color component editing controls -->
|
||||
<!-- Component 1 RGB:Red HSV:Hue -->
|
||||
@ -560,4 +564,142 @@
|
||||
</Style>
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
|
||||
<ControlTheme x:Key="SimpleColorView" TargetType="ColorView">
|
||||
<Setter Property="Width" Value="280" />
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
|
||||
<Setter Property="ColorSpectrumComponents" Value="SaturationValue" />
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="{x:Type ColorView}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" MinHeight="280" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<!-- Spectrum Tab -->
|
||||
<Border
|
||||
Grid.Row="0"
|
||||
CornerRadius="8 8 0 0"
|
||||
ClipToBounds="True">
|
||||
<primitives:ColorSpectrum
|
||||
x:Name="ColorSpectrum"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Components="{TemplateBinding ColorSpectrumComponents}"
|
||||
HsvColor="{TemplateBinding HsvColor, Mode=TwoWay}"
|
||||
MaxHue="{TemplateBinding MaxHue}"
|
||||
MaxSaturation="{TemplateBinding MaxSaturation}"
|
||||
MaxValue="{TemplateBinding MaxValue}"
|
||||
MinHue="{TemplateBinding MinHue}"
|
||||
MinSaturation="{TemplateBinding MinSaturation}"
|
||||
MinValue="{TemplateBinding MinValue}"
|
||||
Shape="{TemplateBinding ColorSpectrumShape}" />
|
||||
</Border>
|
||||
<primitives:ColorSlider
|
||||
x:Name="ColorSpectrumThirdComponentSlider"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Third Component"
|
||||
ColorComponent="{Binding #ColorSpectrum.ThirdComponent}"
|
||||
ColorModel="Hsva"
|
||||
HsvColor="{TemplateBinding HsvColor, Mode=TwoWay}"
|
||||
IsVisible="{TemplateBinding IsColorSpectrumSliderVisible}"
|
||||
Orientation="Horizontal" />
|
||||
|
||||
<primitives:ColorSlider
|
||||
x:Name="ColorSpectrumAlphaSlider"
|
||||
Grid.Row="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Alpha Component"
|
||||
ColorComponent="Alpha"
|
||||
ColorModel="Hsva"
|
||||
HsvColor="{TemplateBinding HsvColor, Mode=TwoWay}"
|
||||
IsEnabled="{TemplateBinding IsAlphaEnabled}"
|
||||
IsVisible="{TemplateBinding IsAlphaVisible}"
|
||||
IsRoundingEnabled="True"
|
||||
IsSnapToTickEnabled="True"
|
||||
TickFrequency="1"
|
||||
Orientation="Horizontal">
|
||||
</primitives:ColorSlider>
|
||||
<StackPanel
|
||||
Grid.Row="3"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
Margin="0 8 0 0">
|
||||
<Border
|
||||
Background="{TemplateBinding Color, Converter={StaticResource ToBrushConverter}}"
|
||||
Width="20"
|
||||
Height="20"
|
||||
CornerRadius="4" />
|
||||
<Panel
|
||||
x:Name="PART_TextBoxPanel"
|
||||
Width="106"
|
||||
Margin="4 0 0 0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center">
|
||||
<TextBox
|
||||
x:Name="PART_HexTextBox"
|
||||
Classes="Small"
|
||||
InnerLeftContent="#"
|
||||
IsVisible="{Binding #ColorModelComboBox.SelectedValue, Converter={StaticResource ToColorModel}, ConverterParameter=Hex}"
|
||||
Text="{TemplateBinding Color, Converter={StaticResource ColorToHexConverter}, Mode=TwoWay}"
|
||||
MaxLength="8" />
|
||||
<TextBox
|
||||
x:Name="PART_RgbaTextBox"
|
||||
Classes="Small"
|
||||
IsVisible="{Binding #ColorModelComboBox.SelectedValue, Converter={StaticResource ToColorModel}, ConverterParameter=Rgba}"
|
||||
Text="{TemplateBinding Color, Converter={StaticResource ColorToTextConverter}, Mode=TwoWay}" />
|
||||
<TextBox
|
||||
x:Name="PART_HsvaTextBox"
|
||||
Classes="Small"
|
||||
IsVisible="{Binding #ColorModelComboBox.SelectedValue, Converter={StaticResource ToColorModel}, ConverterParameter=Hsva}"
|
||||
Text="{TemplateBinding HsvColor, Converter={StaticResource HsvColorToTextConverter}, Mode=TwoWay}" />
|
||||
</Panel>
|
||||
|
||||
<NumericUpDown
|
||||
x:Name="AlphaComponentNumericUpDown"
|
||||
Width="70"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
AllowSpin="True"
|
||||
Classes="Small"
|
||||
IsEnabled="{TemplateBinding IsAlphaEnabled}"
|
||||
Maximum="{Binding #ColorSpectrumAlphaSlider.Maximum}"
|
||||
Minimum="{Binding #ColorSpectrumAlphaSlider.Minimum}"
|
||||
NumberFormat="{StaticResource ColorViewComponentNumberFormat}"
|
||||
ShowButtonSpinner="False"
|
||||
InnerRightContent="%"
|
||||
IsVisible="{TemplateBinding IsAlphaVisible}"
|
||||
Value="{Binding #ColorSpectrumAlphaSlider.Value}" />
|
||||
<ComboBox
|
||||
x:Name="ColorModelComboBox"
|
||||
Width="80"
|
||||
VerticalAlignment="Center"
|
||||
Classes="Small"
|
||||
SelectedValue="Hex">
|
||||
Hex<ColorModel>Rgba</ColorModel>
|
||||
<ColorModel>Hsva</ColorModel>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^[IsAlphaVisible=False] /template/ Panel#PART_TextBoxPanel">
|
||||
<Setter Property="Width" Value="176" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
|
||||
<Design.PreviewWith>
|
||||
<ColorView
|
||||
Theme="{StaticResource SimpleColorView}"
|
||||
IsAlphaVisible="True"
|
||||
IsAlphaEnabled="True"
|
||||
ColorModel="Hsva"
|
||||
HsvColor="hsv(120,7%,90%)" />
|
||||
</Design.PreviewWith>
|
||||
</ResourceDictionary>
|
||||
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Semi.Avalonia.ColorPicker.Converters;
|
||||
|
||||
public class ColorToTextConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value is Color color ? $"{color.R},{color.G},{color.B},{color.A}" : AvaloniaProperty.UnsetValue;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not string str) return BindingOperations.DoNothing;
|
||||
var parts = str.Split(',');
|
||||
if (parts.Length != 4 || parts.Any(string.IsNullOrWhiteSpace)) return BindingOperations.DoNothing;
|
||||
|
||||
if (byte.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var r) &&
|
||||
byte.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var g) &&
|
||||
byte.TryParse(parts[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var b) &&
|
||||
byte.TryParse(parts[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out var a))
|
||||
{
|
||||
return new Color(a, r, g, b);
|
||||
}
|
||||
|
||||
return BindingOperations.DoNothing;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Semi.Avalonia.ColorPicker.Converters;
|
||||
|
||||
public class HsvColorToTextConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value is HsvColor hsvColor
|
||||
? $"{Math.Round(hsvColor.H)},{Math.Round(hsvColor.S * 100)},{Math.Round(hsvColor.V * 100)},{Math.Round(hsvColor.A * 100)}"
|
||||
: AvaloniaProperty.UnsetValue;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not string str) return BindingOperations.DoNothing;
|
||||
var parts = str.Split(',');
|
||||
if (parts.Length != 4 || parts.Any(string.IsNullOrWhiteSpace)) return BindingOperations.DoNothing;
|
||||
|
||||
if (double.TryParse(parts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var h) &&
|
||||
double.TryParse(parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var s) &&
|
||||
double.TryParse(parts[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var v) &&
|
||||
double.TryParse(parts[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var a))
|
||||
{
|
||||
return new HsvColor(a / 100, h, s / 100, v / 100);
|
||||
}
|
||||
|
||||
return BindingOperations.DoNothing;
|
||||
}
|
||||
}
|
21
src/Semi.Avalonia.ColorPicker/Converters/ToColorModel.cs
Normal file
21
src/Semi.Avalonia.ColorPicker/Converters/ToColorModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace Semi.Avalonia.ColorPicker.Converters;
|
||||
|
||||
public class ToColorModel : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return parameter is "Hex" && value is "Hex" ||
|
||||
parameter is "Rgba" && value is ColorModel.Rgba ||
|
||||
parameter is "Hsva" && value is ColorModel.Hsva;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -29,4 +29,5 @@
|
||||
<colorPicker:SemiColorDarkPalette x:Key="SemiColorPalette" />
|
||||
|
||||
<PlacementMode x:Key="ColorPickerFlyoutPlacement">AnchorAndGravity</PlacementMode>
|
||||
<PlacementMode x:Key="SimpleColorPickerFlyoutPlacement">BottomEdgeAlignedLeft</PlacementMode>
|
||||
</ResourceDictionary>
|
@ -34,11 +34,10 @@
|
||||
<Grid
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
ColumnDefinitions="*, Auto, Auto">
|
||||
ColumnDefinitions="*, Auto">
|
||||
<TextBox
|
||||
Name="PART_TextBox"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
MinHeight="{TemplateBinding MinHeight}"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
@ -76,7 +75,7 @@
|
||||
</TextBox>
|
||||
<Button
|
||||
Name="ClearButton"
|
||||
Grid.Column="2"
|
||||
Grid.Column="1"
|
||||
Padding="0,0,8,0"
|
||||
Content="{DynamicResource IconButtonClearData}"
|
||||
Command="{Binding $parent[CalendarDatePicker].Clear}"
|
||||
@ -85,7 +84,7 @@
|
||||
Theme="{DynamicResource InnerIconButton}" />
|
||||
<Button
|
||||
Name="PART_Button"
|
||||
Grid.Column="2"
|
||||
Grid.Column="1"
|
||||
Padding="0,0,8,0"
|
||||
Content="{DynamicResource CalendarDatePickerIconGlyph}"
|
||||
Focusable="False"
|
||||
|
@ -46,7 +46,7 @@
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="ComboBox">
|
||||
<DataValidationErrors>
|
||||
<Grid ColumnDefinitions="*, 32">
|
||||
<Grid ColumnDefinitions="*, Auto">
|
||||
<Border
|
||||
x:Name="Background"
|
||||
Grid.Column="0"
|
||||
@ -80,8 +80,10 @@
|
||||
<Button
|
||||
Name="ClearButton"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,8,0"
|
||||
Command="{Binding $parent[ComboBox].Clear}"
|
||||
Content="{DynamicResource IconButtonClearData}"
|
||||
Focusable="False"
|
||||
IsVisible="False"
|
||||
Theme="{DynamicResource InnerIconButton}" />
|
||||
<Border
|
||||
@ -98,9 +100,7 @@
|
||||
Grid.Column="1"
|
||||
Width="12"
|
||||
Height="12"
|
||||
Margin="0,0,10,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,12,0"
|
||||
Data="{DynamicResource ComboBoxIcon}"
|
||||
Foreground="{DynamicResource ComboBoxIconDefaultForeground}"
|
||||
IsHitTestVisible="False"
|
||||
|
Loading…
x
Reference in New Issue
Block a user