diff --git a/demo/Ursa.Demo/App.axaml b/demo/Ursa.Demo/App.axaml index 004d33b..218b0f4 100644 --- a/demo/Ursa.Demo/App.axaml +++ b/demo/Ursa.Demo/App.axaml @@ -5,5 +5,6 @@ xmlns:local="using:Ursa.Demo"> + diff --git a/demo/Ursa.Demo/App.axaml.cs b/demo/Ursa.Demo/App.axaml.cs index 990010b..47a67b5 100644 --- a/demo/Ursa.Demo/App.axaml.cs +++ b/demo/Ursa.Demo/App.axaml.cs @@ -21,7 +21,6 @@ public partial class App : Application { // Line below is needed to remove Avalonia data validation. // Without this line you will get duplicate validations from both Avalonia and CT - ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin); desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel(), diff --git a/demo/Ursa.Demo/Pages/BannerDemo.axaml b/demo/Ursa.Demo/Pages/BannerDemo.axaml new file mode 100644 index 0000000..e7b9630 --- /dev/null +++ b/demo/Ursa.Demo/Pages/BannerDemo.axaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + diff --git a/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs b/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs new file mode 100644 index 0000000..8ea8b76 --- /dev/null +++ b/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs @@ -0,0 +1,48 @@ +using System.Collections.ObjectModel; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Notifications; +using Avalonia.Markup.Xaml; +using Ursa.Demo.ViewModels; + +namespace Ursa.Demo.Pages; + +public partial class BannerDemo : UserControl +{ + public BannerDemo() + { + InitializeComponent(); + this.DataContext = new BannerDemoViewModel(); + } +} + +public class BannerDemoViewModel: ViewModelBase +{ + private ObservableCollection _types; + public ObservableCollection Types + { + get => _types; + set => SetProperty(ref _types, value); + } + + private NotificationType _selectedType; + + public NotificationType SelectedType + { + get => _selectedType; + set => SetProperty(ref _selectedType, value); + } + + private bool _bordered; + + public bool Bordered + { + get => _bordered; + set => SetProperty(ref _bordered, value); + } + + public BannerDemoViewModel() + { + Types = new ObservableCollection() { NotificationType.Information, NotificationType.Warning, NotificationType.Error, NotificationType.Success }; + } +} \ No newline at end of file diff --git a/demo/Ursa.Demo/Ursa.Demo.csproj b/demo/Ursa.Demo/Ursa.Demo.csproj index 81079f9..272045d 100644 --- a/demo/Ursa.Demo/Ursa.Demo.csproj +++ b/demo/Ursa.Demo/Ursa.Demo.csproj @@ -18,12 +18,17 @@ - - + + - + - + + + + + + diff --git a/demo/Ursa.Demo/ViewLocator.cs b/demo/Ursa.Demo/ViewLocator.cs deleted file mode 100644 index 2a2e3cf..0000000 --- a/demo/Ursa.Demo/ViewLocator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Avalonia.Controls; -using Avalonia.Controls.Templates; -using Ursa.Demo.ViewModels; - -namespace Ursa.Demo; - -public class ViewLocator : IDataTemplate -{ - public IControl Build(object data) - { - var name = data.GetType().FullName!.Replace("ViewModel", "View"); - var type = Type.GetType(name); - - if (type != null) - { - return (Control)Activator.CreateInstance(type)!; - } - - return new TextBlock { Text = "Not Found: " + name }; - } - - public bool Match(object data) - { - return data is ViewModelBase; - } -} \ No newline at end of file diff --git a/demo/Ursa.Demo/Views/MainWindow.axaml b/demo/Ursa.Demo/Views/MainWindow.axaml index 98a1707..860266a 100644 --- a/demo/Ursa.Demo/Views/MainWindow.axaml +++ b/demo/Ursa.Demo/Views/MainWindow.axaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:pages="clr-namespace:Ursa.Demo.Pages" xmlns:vm="using:Ursa.Demo.ViewModels" Title="Ursa.Demo" d:DesignHeight="450" @@ -15,12 +16,10 @@ - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/_index.axaml b/src/Ursa.Themes.Semi/Controls/_index.axaml new file mode 100644 index 0000000..8827a5d --- /dev/null +++ b/src/Ursa.Themes.Semi/Controls/_index.axaml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Ursa.Themes.Semi/Index.axaml b/src/Ursa.Themes.Semi/Index.axaml new file mode 100644 index 0000000..5c182e5 --- /dev/null +++ b/src/Ursa.Themes.Semi/Index.axaml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Dark/Banner.axaml b/src/Ursa.Themes.Semi/Themes/Dark/Banner.axaml new file mode 100644 index 0000000..9017e8d --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Dark/Banner.axaml @@ -0,0 +1,3 @@ + + + diff --git a/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml b/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml new file mode 100644 index 0000000..8827a5d --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Dark/_index.axaml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Light/Banner.axaml b/src/Ursa.Themes.Semi/Themes/Light/Banner.axaml new file mode 100644 index 0000000..2fda7f5 --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Light/Banner.axaml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Light/_index.axaml b/src/Ursa.Themes.Semi/Themes/Light/_index.axaml new file mode 100644 index 0000000..8827a5d --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Light/_index.axaml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/Banner.axaml b/src/Ursa.Themes.Semi/Themes/Shared/Banner.axaml new file mode 100644 index 0000000..39a925c --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Shared/Banner.axaml @@ -0,0 +1,12 @@ + + + M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM14 7C14 8.10457 13.1046 9 12 9C10.8954 9 10 8.10457 10 7C10 5.89543 10.8954 5 12 5C13.1046 5 14 5.89543 14 7ZM9 10.75C9 10.3358 9.33579 10 9.75 10H12.5C13.0523 10 13.5 10.4477 13.5 11V16.5H14.25C14.6642 16.5 15 16.8358 15 17.25C15 17.6642 14.6642 18 14.25 18H9.75C9.33579 18 9 17.6642 9 17.25C9 16.8358 9.33579 16.5 9.75 16.5H10.5V11.5H9.75C9.33579 11.5 9 11.1642 9 10.75Z + M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.8831 9.82235L11.6854 17.4112C11.4029 17.7806 10.965 17.9981 10.5 18C10.035 18.0019 9.59533 17.788 9.30982 17.421L5.81604 13.4209C5.30744 12.767 5.42524 11.8246 6.07916 11.316C6.73308 10.8074 7.67549 10.9252 8.1841 11.5791L10.4838 14.0439L15.5 8C16.0032 7.34193 16.9446 7.21641 17.6027 7.71964C18.2608 8.22287 18.3863 9.16428 17.8831 9.82235Z + M10.2268 2.3986L1.52616 19.0749C0.831449 20.4064 1.79747 22 3.29933 22H20.7007C22.2025 22 23.1686 20.4064 22.4739 19.0749L13.7732 2.3986C13.0254 0.965441 10.9746 0.965442 10.2268 2.3986ZM13.1415 14.0101C13.0603 14.5781 12.5739 15 12.0001 15C11.4263 15 10.9398 14.5781 10.8586 14.0101L10.2829 9.97992C10.1336 8.93495 10.9445 8.00002 12.0001 8.00002C13.0556 8.00002 13.8665 8.93495 13.7172 9.97992L13.1415 14.0101ZM13.5001 18.5C13.5001 19.3284 12.8285 20 12.0001 20C11.1716 20 10.5001 19.3284 10.5001 18.5C10.5001 17.6716 11.1716 17 12.0001 17C12.8285 17 13.5001 17.6716 13.5001 18.5Z + M23 12C23 18.0751 18.0751 23 12 23C5.92487 23 1 18.0751 1 12C1 5.92487 5.92487 1 12 1C18.0751 1 23 5.92487 23 12ZM13.5 17.5C13.5 16.6716 12.8284 16 12 16C11.1716 16 10.5 16.6716 10.5 17.5C10.5 18.3284 11.1716 19 12 19C12.8284 19 13.5 18.3284 13.5 17.5ZM12 5C10.9138 5 10.0507 5.91244 10.1109 6.99692L10.4168 12.5023C10.4635 13.3426 11.1584 14 12 14C12.8416 14 13.5365 13.3426 13.5832 12.5023L13.8891 6.99692C13.9493 5.91244 13.0862 5 12 5Z + M 17.6568 19.7782 C 18.2426 20.3639 19.1924 20.3639 19.7782 19.7782 C 20.3639 19.1924 20.3639 18.2426 19.7782 17.6568 L 14.1213 12 L 19.7782 6.34313 C 20.3639 5.75734 20.3639 4.8076 19.7782 4.22181 C 19.1924 3.63602 18.2426 3.63602 17.6568 4.22181 L 12 9.87866 L 6.34313 4.22181 C 5.75734 3.63602 4.8076 3.63602 4.22181 4.22181 C 3.63602 4.8076 3.63602 5.75734 4.22181 6.34313 L 9.87866 12 L 4.22181 17.6568 C 3.63602 18.2426 3.63602 19.1924 4.22181 19.7782 C 4.8076 20.3639 5.75734 20.3639 6.34313 19.7782 L 12 14.1213 L 17.6568 19.7782 Z + + 3 + 1 + 0 0 12 0 + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml b/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml new file mode 100644 index 0000000..8827a5d --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Ursa.Themes.Semi/Ursa.Themes.Semi.csproj b/src/Ursa.Themes.Semi/Ursa.Themes.Semi.csproj index 0e8b4fd..7fb04b2 100644 --- a/src/Ursa.Themes.Semi/Ursa.Themes.Semi.csproj +++ b/src/Ursa.Themes.Semi/Ursa.Themes.Semi.csproj @@ -1,22 +1,19 @@ - net7.0 + netstandard2.0 enable enable + 11 - + - - - - - + diff --git a/src/Ursa/AssemblyInfo.cs b/src/Ursa/AssemblyInfo.cs new file mode 100644 index 0000000..0b0375e --- /dev/null +++ b/src/Ursa/AssemblyInfo.cs @@ -0,0 +1,5 @@ +using Avalonia.Metadata; + +[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa")] +[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls")] +[assembly:XmlnsPrefix("https://irihi.tech/ursa", "u")] \ No newline at end of file diff --git a/src/Ursa/Controls/Banner.cs b/src/Ursa/Controls/Banner.cs new file mode 100644 index 0000000..2049e12 --- /dev/null +++ b/src/Ursa/Controls/Banner.cs @@ -0,0 +1,76 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Notifications; +using Avalonia.Controls.Primitives; +using Avalonia.Controls.Templates; +using Avalonia.Interactivity; +using Avalonia.Metadata; + +namespace Ursa.Controls; + +[PseudoClasses(PC_Icon)] +[TemplatePart(PART_CloseButton, typeof(Button))] +public class Banner: HeaderedContentControl +{ + public const string PC_Icon = ":icon"; + public const string PART_CloseButton = "PART_CloseButton"; + + private Button? _closeButton; + + public static readonly StyledProperty CanCloseProperty = AvaloniaProperty.Register( + nameof(CanClose)); + + public bool CanClose + { + get => GetValue(CanCloseProperty); + set => SetValue(CanCloseProperty, value); + } + + public static readonly StyledProperty ShowIconProperty = AvaloniaProperty.Register( + nameof(ShowIcon), true); + + public bool ShowIcon + { + get => GetValue(ShowIconProperty); + set => SetValue(ShowIconProperty, value); + } + + public static readonly StyledProperty IconProperty = AvaloniaProperty.Register( + nameof(Icon)); + + public object? Icon + { + get => GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + public static readonly StyledProperty TypeProperty = AvaloniaProperty.Register( + nameof(Type)); + + public NotificationType Type + { + get => GetValue(TypeProperty); + set => SetValue(TypeProperty, value); + } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + if (_closeButton != null) + { + _closeButton.Click -= OnCloseClick; + } + _closeButton = e.NameScope.Find