Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CardControl #707

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/CardControlViewModel.cs
Original file line number Diff line number Diff line change
@@ -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() { }
}
7 changes: 6 additions & 1 deletion src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Page
x:Class="Wpf.Ui.Gallery.Views.Pages.Layout.CardControlPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Wpf.Ui.Gallery.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.Ui.Gallery.Views.Pages.Layout"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="CardControlPage"
d:DesignHeight="450"
d:DesignWidth="800"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">

<controls:ControlExample
Margin="0"
HeaderText="A card control with a header and a button."
XamlCode="&lt;ui:CardControl Header=&quot;This is the header text.&quot; /&gt;">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:CardControl Grid.Column="0">
<ui:CardControl.Header>
<TextBlock Text="This is the header text." />
</ui:CardControl.Header>
<ui:CardControl.Content>
<ui:Button Content="Button" />
</ui:CardControl.Content>
</ui:CardControl>

</Grid>
</controls:ControlExample>
<!-- TODO: Add CardAction -->
</Page>
38 changes: 38 additions & 0 deletions src/Wpf.Ui.Gallery/Views/Pages/Layout/CardControlPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
/// <summary>
/// Interaction logic for CardControlPage.xaml
/// </summary>
[GalleryPage("Card control.", SymbolRegular.CardUi24)]
public partial class CardControlPage : INavigableView<CardControlViewModel>
{
public CardControlPage(CardControlViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
}

public CardControlViewModel ViewModel { get; }
}
73 changes: 73 additions & 0 deletions src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 27 additions & 1 deletion src/Wpf.Ui/Controls/CardControl/CardControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -31,6 +35,13 @@ public class CardControl : System.Windows.Controls.Primitives.ButtonBase, IIconC
new PropertyMetadata(null)
);

/// <summary>
/// Property for <see cref="CornerRadius"/>
/// </summary>
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(nameof(CornerRadius),
typeof(CornerRadius), typeof(CardControl),
new PropertyMetadata(new CornerRadius(0)));

/// <summary>
/// Header is the data used to for the header of each item in the control.
/// </summary>
Expand All @@ -50,4 +61,19 @@ public IconElement? Icon
get => (IconElement)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}

/// <summary>
/// Gets or sets the corner radius of the control.
/// </summary>
[Bindable(true), Category("Appearance")]
public CornerRadius CornerRadius
{
get => (CornerRadius)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new CardControlAutomationPeer(this);
}
}
4 changes: 2 additions & 2 deletions src/Wpf.Ui/Controls/CardControl/CardControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
Expand All @@ -53,7 +53,7 @@
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
CornerRadius="{TemplateBinding CornerRadius}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down
Loading