فهرست منبع

avalonia: Added ListViewButton

Kenric Nugteren 4 ماه پیش
والد
کامیت
0ac8c26e58

+ 65 - 0
InABox.Avalonia/Components/ListViewButton/ListViewButton.cs

@@ -0,0 +1,65 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Markup.Xaml;
+using Avalonia.Media;
+using System.Windows.Input;
+
+namespace InABox.Avalonia.Components;
+
+public partial class ListViewButton : TemplatedControl
+{
+    public static readonly StyledProperty<IImage?> ImageProperty =
+        AvaloniaProperty.Register<ListViewButton, IImage?>(nameof(Image), null);
+
+    public static readonly StyledProperty<string> TitleProperty =
+        AvaloniaProperty.Register<ListViewButton, string>(nameof(Title), "");
+
+    public static readonly StyledProperty<string> DescriptionProperty =
+        AvaloniaProperty.Register<ListViewButton, string>(nameof(Description), "");
+
+    public static readonly StyledProperty<string> AlertProperty =
+        AvaloniaProperty.Register<ListViewButton, string>(nameof(Alert), "");
+
+    public IImage? Image
+    {
+        get => GetValue(ImageProperty);
+        set => SetValue(ImageProperty, value);
+    }
+
+    public string Title
+    {
+        get => GetValue(TitleProperty);
+        set => SetValue(TitleProperty, value);
+    }
+
+    public string Description
+    {
+        get => GetValue(DescriptionProperty);
+        set => SetValue(DescriptionProperty, value);
+    }
+
+    public string Alert
+    {
+        get => GetValue(AlertProperty);
+        set => SetValue(AlertProperty, value);
+    }
+
+    public static readonly StyledProperty<object?> CommandParameterProperty =
+        AvaloniaProperty.Register<ListViewButton, object?>(nameof(CommandParameter), null);
+
+    public object? CommandParameter
+    {
+        get => GetValue(CommandParameterProperty);
+        set => SetValue(CommandParameterProperty, value);
+    }
+
+    public static readonly StyledProperty<ICommand?> CommandProperty =
+        AvaloniaProperty.Register<ListViewButton, ICommand?>(nameof(Command), null);
+   
+    public ICommand? Command
+    {
+        get => GetValue(CommandProperty);
+        set => SetValue(CommandProperty, value);
+    }
+}

+ 0 - 4
InABox.Avalonia/InABox.Avalonia.csproj

@@ -64,10 +64,6 @@
       </Compile>
     </ItemGroup>
 
-    <ItemGroup>
-      <Folder Include="Components\Modules\" />
-    </ItemGroup>
-
     <ItemGroup>
       <UpToDateCheckInput Remove="Dialogs\TextBoxDialog\TextBoxDialogView.axaml" />
     </ItemGroup>

+ 91 - 0
InABox.Avalonia/Theme/Classes/ListViewButton.axaml

@@ -0,0 +1,91 @@
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+		xmlns:components="using:InABox.Avalonia.Components"
+		xmlns:converters="using:InABox.Avalonia.Converters">
+	<Style Selector="components|ListViewButton">
+		<Style.Resources>
+			<converters:DoubleToCornerRadiusConverter
+				x:Key="SphericalBorder"
+				Ratio="0.5" />
+
+			<converters:DoubleToThicknessConverter
+				x:Key="MarginDoubler"
+				Ratio="2.0" />
+		</Style.Resources>
+		<Setter Property="Template">
+			<ControlTemplate>
+				<Button Height="80"
+						Padding="0"
+						Background="{TemplateBinding Background}"
+						Foreground="{TemplateBinding Foreground}"
+						BorderBrush="{StaticResource PrsTileBorder}"
+						HorizontalContentAlignment="Stretch"
+						VerticalContentAlignment="Stretch"
+						Command="{TemplateBinding Command}"
+						CommandParameter="{TemplateBinding CommandParameter}">
+					<Grid>
+
+						<Grid.RowDefinitions>
+							<RowDefinition Height="*" />
+							<RowDefinition Height="1.2*" />
+						</Grid.RowDefinitions>
+
+						<Grid.ColumnDefinitions>
+							<ColumnDefinition Width="70" />
+							<ColumnDefinition Width="*" />
+						</Grid.ColumnDefinitions>
+
+						<Image
+							Classes="Large"
+							Grid.Row="0"
+							Grid.Column="0"
+							Grid.RowSpan="2"
+							Source="{TemplateBinding Image}"
+							HorizontalAlignment="Center"
+							VerticalAlignment="Center" />
+
+						<Label
+							Grid.Row="0"
+							Grid.Column="1"
+							VerticalAlignment="Stretch"
+							VerticalContentAlignment="Center"
+							FontSize="{StaticResource PrsFontSizeLarge}"
+							FontWeight="{StaticResource PrsFontWeightBold}"
+							Content="{TemplateBinding Title}" />
+
+						<TextBlock
+							Grid.Row="1"
+							Grid.Column="1"
+							FontSize="{StaticResource PrsFontSizeNormal}"
+							FontStyle="{StaticResource PrsFontStylItalic}"
+							TextWrapping="WrapWithOverflow"
+							VerticalAlignment="Stretch"
+							Text="{TemplateBinding Description}" />
+
+						<Border
+							Background="{StaticResource PrsTileBackground}"
+							BorderBrush="{StaticResource PrsTileBorder}"
+							Grid.Row="0"
+							Grid.RowSpan="2"
+							Grid.Column="1"
+							VerticalAlignment="Top"
+							HorizontalAlignment="Right"
+							IsVisible="{TemplateBinding Alert, Converter={StaticResource StringToBooleanConverter}}"
+							MinWidth="{Binding $self.Bounds.Height}"
+							Margin="{Binding $self, Converter={StaticResource MarginDoubler}, ConverterParameter={StaticResource PrsControlSpacing}}"
+							CornerRadius="{Binding $self.Bounds.Height, Converter={StaticResource SphericalBorder}}">
+
+							<Label
+								Background="Transparent"
+								Foreground="{StaticResource PrsTileForeground}"
+								HorizontalContentAlignment="Center"
+								Content="{TemplateBinding Alert}" />
+						</Border>
+
+					</Grid>
+				</Button>
+			</ControlTemplate>
+		</Setter>
+	</Style>
+
+</Styles>