Skip to content

Commit

Permalink
test: x:Bind to event in ResourceDictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 6, 2023
1 parent e7a3e36 commit 767fb71
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<ResourceDictionary
x:Class="Uno.UI.Tests.Windows_UI_Xaml_Data.xBindTests.Controls.XBind_ResourceDictionary"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Uno.UI.Tests.Windows_UI_Xaml_Data.xBindTests.Controls">

<!-- Implicitly applied default style -->
<Style BasedOn="{StaticResource DefaultxBindProjectTemplateStyle}" TargetType="controls:XBind_ResourceDictionary_Control" />

<Style x:Key="DefaultxBindProjectTemplateStyle" TargetType="controls:XBind_ResourceDictionary_Control">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:XBind_ResourceDictionary_Control">
<ContentControl
x:Name="ContentContainer"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<ContentControl.ContentTemplate>
<DataTemplate x:DataType="controls:XBind_ResourceDictionary_Control">
<Button Content="Hello" Loaded="{x:Bind Element_Loaded}" />
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace Uno.UI.Tests.Windows_UI_Xaml_Data.xBindTests.Controls;
public sealed partial class XBind_ResourceDictionary : ResourceDictionary
{
public XBind_ResourceDictionary()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Uno.UI.Tests.Windows_UI_Xaml_Data.xBindTests.Controls;

internal class XBind_ResourceDictionary_Control : Control
{
/// <summary>
/// Creates a new instance of the <see cref="ProjectTemplate_xBind"/> class.
/// </summary>
public XBind_ResourceDictionary_Control()
{
this.DefaultStyleKey = typeof(XBind_ResourceDictionary_Control);

// Allows directly using this control as the x:DataType in the template.
this.DataContext = this;
}

public bool ElementLoadedInvoked { get; private set; }

public void Element_Loaded(object sender, RoutedEventArgs args)
{
ElementLoadedInvoked = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,15 @@ public void When_Indexer_Then_Property_Access_Update_Collection_Element()
Assert.AreEqual("Updated2", SUT.tbDict2.Text);
}

[TestMethod]
public void When_XBind_In_ResourceDictionary()
{
var SUT = new XBind_ResourceDictionary_Control();
SUT.ForceLoaded();

Assert.IsTrue(SUT.ElementLoadedInvoked);
}

private async Task AssertIsNullAsync<T>(Func<T> getter, TimeSpan? timeout = null) where T : class
{
timeout ??= TimeSpan.FromSeconds(1);
Expand Down

0 comments on commit 767fb71

Please sign in to comment.