SetterTests.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Avalonia.Controls;
  2. using Avalonia.Styling;
  3. using Avalonia.UnitTests;
  4. using Xunit;
  5. namespace Avalonia.Markup.Xaml.UnitTests;
  6. public class SetterTests : XamlTestBase
  7. {
  8. [Fact]
  9. public void SetterTargetType_Should_Understand_xType_Extensions()
  10. {
  11. using (UnitTestApplication.Start(TestServices.StyledWindow))
  12. {
  13. var xaml = @"
  14. <Animation xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:SetterTargetType='{x:Type ContentControl}'>
  15. <KeyFrame>
  16. <Setter Property='Content' Value='{Binding}'/>
  17. </KeyFrame>
  18. <KeyFrame>
  19. <Setter Property='Content' Value='{Binding}'/>
  20. </KeyFrame>
  21. </Animation>";
  22. var animation = (Animation.Animation)AvaloniaRuntimeXamlLoader.Load(xaml);
  23. var setter = (Setter)animation.Children[0].Setters[0];
  24. Assert.Equal(typeof(ContentControl), setter.Property.OwnerType);
  25. }
  26. }
  27. [Fact]
  28. public void SetterTargetType_Should_Understand_Type_From_Xmlns()
  29. {
  30. using (UnitTestApplication.Start(TestServices.StyledWindow))
  31. {
  32. var xaml = @"
  33. <av:Animation xmlns:av='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:SetterTargetType='av:ContentControl'>
  34. <av:KeyFrame>
  35. <av:Setter Property='Content' Value='{av:Binding}'/>
  36. </av:KeyFrame>
  37. <av:KeyFrame>
  38. <av:Setter Property='Content' Value='{av:Binding}'/>
  39. </av:KeyFrame>
  40. </av:Animation>";
  41. var animation = (Animation.Animation)AvaloniaRuntimeXamlLoader.Load(xaml);
  42. var setter = (Setter)animation.Children[0].Setters[0];
  43. Assert.Equal(typeof(ContentControl), setter.Property.OwnerType);
  44. }
  45. }
  46. }