Skip to content

Commit 1f4a020

Browse files
Fix default elevation of Card Flipper (#2801)
* Fix default elevation of Card Flipper The UI test fails because of the static ctor in FlipperAssist. I was unable to get this to work and may need some input on how to get it to locate the resource with the Uri when executing in the MaterialDesignThemes.UITests context. * Separating the loading of resources from the attached properties Co-authored-by: Kevin Bost <[email protected]>
1 parent 4b980db commit 1f4a020

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

MaterialDesignThemes.UITests/WPF/Flippers/FlipperTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MaterialDesignThemes.UITests.WPF.Flippers;
1+
namespace MaterialDesignThemes.UITests.WPF.Flippers;
22

33
public class FlipperTests : TestBase
44
{
@@ -51,4 +51,24 @@ public async Task Flipper_UniformCornerRadiusAndElevatedCardStyleAttachedPropert
5151

5252
recorder.Success();
5353
}
54+
55+
[Fact]
56+
public async Task Flipper_ElevatedCardStyleApplied_AppliesDefaultElevation()
57+
{
58+
await using var recorder = new TestRecorder(App);
59+
60+
//Arrange
61+
IVisualElement<Flipper> flipper = await LoadXaml<Flipper>(
62+
@"<materialDesign:Flipper Style=""{StaticResource MaterialDesignCardFlipper}"" materialDesign:FlipperAssist.CardStyle=""{StaticResource MaterialDesignElevatedCard}"" />");
63+
IVisualElement<Card> internalCard = await flipper.GetElement<Card>();
64+
65+
//Act
66+
// TODO: This throws an exception because it fails to load the 'MaterialDesignTheme.Shadows.xaml' resource dictionary in the ElevationAssist static ctor
67+
Elevation? defaultElevation = await internalCard.GetProperty<Elevation>(ElevationAssist.ElevationProperty);
68+
69+
//Assert
70+
Assert.Equal(Elevation.Dp1, defaultElevation);
71+
72+
recorder.Success();
73+
}
5474
}

MaterialDesignThemes.Wpf/ElevationAssist.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ public enum Elevation
1818
Dp24
1919
}
2020

21-
public static class ElevationAssist
21+
internal static class ElevationInfo
2222
{
2323
private static readonly IDictionary<Elevation, DropShadowEffect?> ShadowsDictionary;
2424

25-
public static readonly DependencyProperty ElevationProperty = DependencyProperty.RegisterAttached(
26-
"Elevation",
27-
typeof(Elevation),
28-
typeof(ElevationAssist),
29-
new FrameworkPropertyMetadata(default(Elevation), FrameworkPropertyMetadataOptions.AffectsRender));
30-
31-
static ElevationAssist()
25+
static ElevationInfo()
3226
{
3327
const string shadowsUri = "pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml";
3428
var resourceDictionary = new ResourceDictionary { Source = new Uri(shadowsUri, UriKind.Absolute) };
@@ -50,8 +44,20 @@ static ElevationAssist()
5044
};
5145
}
5246

47+
public static DropShadowEffect? GetDropShadow(Elevation elevation) => ShadowsDictionary[elevation];
48+
}
49+
50+
public static class ElevationAssist
51+
{
52+
53+
public static readonly DependencyProperty ElevationProperty = DependencyProperty.RegisterAttached(
54+
"Elevation",
55+
typeof(Elevation),
56+
typeof(ElevationAssist),
57+
new FrameworkPropertyMetadata(default(Elevation), FrameworkPropertyMetadataOptions.AffectsRender));
58+
5359
public static void SetElevation(DependencyObject element, Elevation value) => element.SetValue(ElevationProperty, value);
5460
public static Elevation GetElevation(DependencyObject element) => (Elevation)element.GetValue(ElevationProperty);
5561

56-
public static DropShadowEffect? GetDropShadow(Elevation elevation) => ShadowsDictionary[elevation];
62+
public static DropShadowEffect? GetDropShadow(Elevation elevation) => ElevationInfo.GetDropShadow(elevation);
5763
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Flipper.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
</Style>
9898

9999
<Style x:Key="MaterialDesignCardFlipper" TargetType="{x:Type wpf:Flipper}" BasedOn="{StaticResource {x:Type wpf:Flipper}}">
100+
<Setter Property="wpf:ElevationAssist.Elevation" Value="Dp1" />
100101
<Setter Property="Template">
101102
<Setter.Value>
102103
<ControlTemplate TargetType="{x:Type wpf:Flipper}">

0 commit comments

Comments
 (0)