Skip to content

Commit fa9c3b2

Browse files
authored
fix(controls): CardExpander has inconsistent CornerRadius (#1577)
* fix(controls): CardExpander has inconsistent CornerRadius * Add System.Windows.Data using directive
1 parent d686224 commit fa9c3b2

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

src/Wpf.Ui/Controls/CardExpander/CardExpander.xaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<ControlTemplate TargetType="{x:Type controls:CardExpander}">
109109
<ControlTemplate.Resources>
110110
<converters:AnimationFactorToValueConverter x:Key="AnimationFactorToValueConverter" />
111+
<converters:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
111112
</ControlTemplate.Resources>
112113

113114
<Grid>
@@ -122,8 +123,13 @@
122123
Grid.Row="0"
123124
Background="{TemplateBinding Background}"
124125
BorderBrush="{TemplateBinding BorderBrush}"
125-
BorderThickness="1"
126-
CornerRadius="{TemplateBinding CornerRadius}">
126+
BorderThickness="1">
127+
<Border.CornerRadius>
128+
<MultiBinding Converter="{StaticResource CornerRadiusSplitConverter}" ConverterParameter="Top">
129+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="CornerRadius" />
130+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="IsExpanded" />
131+
</MultiBinding>
132+
</Border.CornerRadius>
127133
<ToggleButton
128134
x:Name="ExpanderToggleButton"
129135
Margin="0"
@@ -173,8 +179,13 @@
173179
Background="{DynamicResource CardBackground}"
174180
BorderBrush="{TemplateBinding BorderBrush}"
175181
BorderThickness="1,0,1,1"
176-
CornerRadius="0,0,4,4"
177182
Visibility="Collapsed">
183+
<Border.CornerRadius>
184+
<MultiBinding Converter="{StaticResource CornerRadiusSplitConverter}" ConverterParameter="Bottom" >
185+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="CornerRadius" />
186+
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="IsExpanded" />
187+
</MultiBinding>
188+
</Border.CornerRadius>
178189
<ContentPresenter
179190
x:Name="ContentPresenter"
180191
Margin="{TemplateBinding ContentPadding}"
@@ -197,7 +208,6 @@
197208
<ControlTemplate.Triggers>
198209
<Trigger Property="IsExpanded" Value="True">
199210
<!-- TODO: Update -->
200-
<Setter TargetName="ToggleButtonBorder" Property="CornerRadius" Value="4,4,0,0" />
201211
<Trigger.EnterActions>
202212
<BeginStoryboard>
203213
<Storyboard>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This Source Code Form is subject to the terms of the MIT License.
2+
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
3+
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
4+
// All Rights Reserved.
5+
6+
namespace Wpf.Ui.Converters;
7+
8+
using System.Windows.Data;
9+
10+
public class CornerRadiusSplitConverter : IMultiValueConverter
11+
{
12+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
var original = new CornerRadius(0);
15+
if (values.Length > 0 && values[0] is CornerRadius cornerRadius)
16+
{
17+
original = cornerRadius;
18+
}
19+
20+
bool isExpanded = false;
21+
if (values.Length > 1 && values[1] is bool isExpand)
22+
{
23+
isExpanded = isExpand;
24+
}
25+
26+
var side = (parameter as string) ?? "Top";
27+
28+
if (string.Equals(side, "Top", StringComparison.OrdinalIgnoreCase))
29+
{
30+
return isExpanded
31+
? new CornerRadius(original.TopLeft, original.TopRight, 0, 0)
32+
: original;
33+
}
34+
else
35+
{
36+
return isExpanded
37+
? new CornerRadius(0, 0, original.BottomRight, original.BottomLeft)
38+
: new CornerRadius(0);
39+
}
40+
}
41+
42+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
43+
=> throw new NotSupportedException();
44+
}

0 commit comments

Comments
 (0)