Skip to content
Open
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
18 changes: 14 additions & 4 deletions src/Wpf.Ui/Controls/CardExpander/CardExpander.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<ControlTemplate TargetType="{x:Type controls:CardExpander}">
<ControlTemplate.Resources>
<converters:AnimationFactorToValueConverter x:Key="AnimationFactorToValueConverter" />
<converters:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
</ControlTemplate.Resources>

<Grid>
Expand All @@ -120,8 +121,13 @@
Grid.Row="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
CornerRadius="{TemplateBinding CornerRadius}">
BorderThickness="1">
<Border.CornerRadius>
<MultiBinding Converter="{StaticResource CornerRadiusSplitConverter}" ConverterParameter="Top">
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="CornerRadius"/>
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="IsExpanded"/>
</MultiBinding>
</Border.CornerRadius>
<ToggleButton
x:Name="ExpanderToggleButton"
Margin="0"
Expand Down Expand Up @@ -171,8 +177,13 @@
Background="{DynamicResource CardBackground}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1,0,1,1"
CornerRadius="0,0,4,4"
Visibility="Collapsed">
<Border.CornerRadius>
<MultiBinding Converter="{StaticResource CornerRadiusSplitConverter}" ConverterParameter="Bottom">
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="CornerRadius"/>
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="IsExpanded"/>
</MultiBinding>
</Border.CornerRadius>
<ContentPresenter
x:Name="ContentPresenter"
Margin="{TemplateBinding ContentPadding}"
Expand All @@ -195,7 +206,6 @@
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<!-- TODO: Update -->
<Setter TargetName="ToggleButtonBorder" Property="CornerRadius" Value="4,4,0,0" />
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
Expand Down
44 changes: 44 additions & 0 deletions src/Wpf.Ui/Converters/CornerRadiusSplitConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.Windows.Data;

namespace Wpf.Ui.Converters;

public class CornerRadiusSplitConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var original = new CornerRadius(0);
if (values.Length > 0 && values[0] is CornerRadius cornerRadius)
{
original = cornerRadius;
}

bool isExpanded = false;
if (values.Length > 1 && values[1] is bool isExpand)
{
isExpanded = isExpand;
}

var side = (parameter as string) ?? "Top";

if (string.Equals(side, "Top", StringComparison.OrdinalIgnoreCase))
{
return isExpanded
? new CornerRadius(original.TopLeft, original.TopRight, 0, 0)
: original;
}
else
{
return isExpanded
? new CornerRadius(0, 0, original.BottomRight, original.BottomLeft)
: new CornerRadius(0);
}
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}