diff --git a/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/CardControlViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/CardControlViewModel.cs new file mode 100644 index 000000000..250490978 --- /dev/null +++ b/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/CardControlViewModel.cs @@ -0,0 +1,11 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +namespace Wpf.Ui.Gallery.ViewModels.Pages.Layout; + +public partial class CardControlViewModel : ObservableObject +{ + public CardControlViewModel() { } +} diff --git a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs index 6ae5b4a88..bd00ffc8d 100644 --- a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs +++ b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs @@ -102,7 +102,12 @@ public partial class MainWindowViewModel : ObservableObject #if DEBUG new NavigationViewItem("Layout", SymbolRegular.News24, typeof(LayoutPage)) { - MenuItems = new object[] { new NavigationViewItem("Expander", typeof(ExpanderPage)) } + MenuItems = new object[] + { + new NavigationViewItem("Expander", typeof(ExpanderPage)), + new NavigationViewItem("CardControl", typeof(CardControlPage)) + }, + }, #endif new NavigationViewItem diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml b/src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml new file mode 100644 index 000000000..d41d57c5c --- /dev/null +++ b/src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml.cs b/src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml.cs new file mode 100644 index 000000000..bc34b785b --- /dev/null +++ b/src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml.cs @@ -0,0 +1,38 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Wpf.Ui.Controls; +using Wpf.Ui.Gallery.ControlsLookup; +using Wpf.Ui.Gallery.ViewModels.Pages.Layout; + +namespace Wpf.Ui.Gallery.Views.Pages.Layout; +/// +/// Interaction logic for CardControlPage.xaml +/// +[GalleryPage("Card control.", SymbolRegular.CardUi24)] +public partial class CardControlPage : INavigableView +{ + public CardControlPage(CardControlViewModel viewModel) + { + InitializeComponent(); + ViewModel = viewModel; + } + + public CardControlViewModel ViewModel { get; } +} diff --git a/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs b/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs new file mode 100644 index 000000000..353a96b03 --- /dev/null +++ b/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Automation.Peers; +using Wpf.Ui.Controls; + +namespace Wpf.Ui.AutomationPeers; + +internal class CardControlAutomationPeer : FrameworkElementAutomationPeer +{ + private readonly CardControl _owner; + + public CardControlAutomationPeer(CardControl owner) : base(owner) + { + this._owner = owner; + } + + protected override string GetClassNameCore() + { + return "CardControl"; + } + + protected override AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Pane; + } + + public override object GetPattern(PatternInterface patternInterface) + { + if (patternInterface == PatternInterface.ItemContainer) + { + return this; + } + + return base.GetPattern(patternInterface); + } + + protected override AutomationPeer GetLabeledByCore() + { + if (this._owner.Header is UIElement element) + { + return CreatePeerForElement(element); + } + + return base.GetLabeledByCore(); + } + + protected override string GetNameCore() + { + string result = base.GetNameCore() ?? String.Empty; + + if (result == String.Empty) + { + result = AutomationProperties.GetName(this._owner); + } + + if (result == String.Empty && this._owner.Header is DependencyObject d) + { + result = AutomationProperties.GetName(d); + } + + if (result == String.Empty && this._owner.Header is string s) + { + result = s; + } + + return result; + } +} \ No newline at end of file diff --git a/src/Wpf.Ui/Controls/CardControl/CardControl.cs b/src/Wpf.Ui/Controls/CardControl/CardControl.cs index 9d1446b66..300622e99 100644 --- a/src/Wpf.Ui/Controls/CardControl/CardControl.cs +++ b/src/Wpf.Ui/Controls/CardControl/CardControl.cs @@ -3,7 +3,11 @@ // Copyright (C) Leszek Pomianowski and WPF UI Contributors. // All Rights Reserved. -// ReSharper disable once CheckNamespace +using System.ComponentModel; +using System.Windows; +using System.Windows.Automation.Peers; +using Wpf.Ui.AutomationPeers; + namespace Wpf.Ui.Controls; /// @@ -31,6 +35,13 @@ public class CardControl : System.Windows.Controls.Primitives.ButtonBase, IIconC new PropertyMetadata(null) ); + /// + /// Property for + /// + public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(nameof(CornerRadius), + typeof(CornerRadius), typeof(CardControl), + new PropertyMetadata(new CornerRadius(0))); + /// /// Header is the data used to for the header of each item in the control. /// @@ -50,4 +61,19 @@ public IconElement? Icon get => (IconElement)GetValue(IconProperty); set => SetValue(IconProperty, value); } + + /// + /// Gets or sets the corner radius of the control. + /// + [Bindable(true), Category("Appearance")] + public CornerRadius CornerRadius + { + get => (CornerRadius)GetValue(CornerRadiusProperty); + set => SetValue(CornerRadiusProperty, value); + } + + protected override AutomationPeer OnCreateAutomationPeer() + { + return new CardControlAutomationPeer(this); + } } diff --git a/src/Wpf.Ui/Controls/CardControl/CardControl.xaml b/src/Wpf.Ui/Controls/CardControl/CardControl.xaml index 9cc3d81e3..1c33c7e63 100644 --- a/src/Wpf.Ui/Controls/CardControl/CardControl.xaml +++ b/src/Wpf.Ui/Controls/CardControl/CardControl.xaml @@ -35,7 +35,7 @@ - + @@ -53,7 +53,7 @@ Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" - CornerRadius="{TemplateBinding Border.CornerRadius}"> + CornerRadius="{TemplateBinding CornerRadius}">