BindingTests_TemplatedParent.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System.Linq;
  4. using System.Reactive.Linq;
  5. using Avalonia.Controls;
  6. using Avalonia.UnitTests;
  7. using Avalonia.VisualTree;
  8. using Xunit;
  9. namespace Avalonia.Markup.Xaml.UnitTests.Data
  10. {
  11. public class BindingTests_TemplatedParent
  12. {
  13. [Fact]
  14. public void TemplateBinding_With_Null_Path_Works()
  15. {
  16. using (UnitTestApplication.Start(TestServices.StyledWindow))
  17. {
  18. var xaml = @"
  19. <Window xmlns='https://github.com/avaloniaui'
  20. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  21. xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'>
  22. <Button Name='button'>
  23. <Button.Template>
  24. <ControlTemplate>
  25. <TextBlock Tag='{TemplateBinding}'/>
  26. </ControlTemplate>
  27. </Button.Template>
  28. </Button>
  29. </Window>";
  30. var loader = new AvaloniaXamlLoader();
  31. var window = (Window)loader.Load(xaml);
  32. var button = window.FindControl<Button>("button");
  33. window.ApplyTemplate();
  34. button.ApplyTemplate();
  35. var textBlock = (TextBlock)button.GetVisualChildren().Single();
  36. Assert.Same(button, textBlock.Tag);
  37. }
  38. }
  39. }
  40. }