Skip to content

Commit

Permalink
Merge pull request #17704 from unoplatform/dev/mazi/themeres-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund authored Jul 27, 2024
2 parents 93bfa70 + 9089688 commit 1ac8296
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<UserControl
x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls.ThemeResource_Refresh_On_Loading"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid>
<Grid.Resources>
<ResourceDictionary>
<Thickness x:Key="DatePickerHostPadding">40,40,40,40</Thickness>
</ResourceDictionary>
</Grid.Resources>

<Border Background="Red" Width="150" Height="150">
<ContentControl x:Name="ContentOwner" />
</Border>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls;

public sealed partial class ThemeResource_Refresh_On_Loading : UserControl
{
public ThemeResource_Refresh_On_Loading()
{
this.InitializeComponent();
}

public void SetContent(UIElement content)
{
ContentOwner.Content = content;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Private.Infrastructure;
using Uno.UI.RuntimeTests.Helpers;
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls;
using Windows.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
using MUXControlsTestApp.Utilities;
using Uno.UI.RuntimeTests.Helpers;
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls;
using Windows.UI;
using static Private.Infrastructure.TestServices;

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml
Expand Down Expand Up @@ -195,6 +190,28 @@ public async Task When_Theme_Changed()
}
}

[TestMethod]
public async Task When_Refresh_On_Loading()
{
using var _ = StyleHelper.UseFluentStyles();
var userControl = new ThemeResource_Refresh_On_Loading();
WindowHelper.WindowContent = userControl;
await WindowHelper.WaitForLoaded(userControl);

var expected = new Thickness(40);

var loaded = false;
var datePicker = new DatePicker();
datePicker.Loaded += (s, e) => loaded = true;
userControl.SetContent(datePicker);

await WindowHelper.WaitFor(() => loaded);

var datePart = (TextBlock)datePicker.FindVisualChildByName("DayTextBlock");

Assert.AreEqual(expected, datePart.Padding);
}

private async Task When_DefaultForeground(Color lightThemeColor, Color darkThemeColor)
{
var run = new Run()
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI.Tests/Windows_UI_Xaml/Given_xLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void When_xLoad_DataTemplate_In_ResDict()
Assert.AreEqual("[SolidColorBrush #FFFF0000]", tb02.Foreground?.ToString());

var tb01 = SUT.FindName("tb01") as TextBlock;
// This assertion is incorrect because of https://github.com/unoplatform/uno/issues/6700
Assert.AreEqual("[SolidColorBrush #FF000000]", tb01.Foreground?.ToString());

Assert.AreEqual("[SolidColorBrush #FFFF0000]", tb01.Foreground?.ToString());
}
}
}
5 changes: 2 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/DatePicker/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ protected override void OnApplyTemplate()
m_tpMonthTextBlock = null;
m_tpDayTextBlock = null;

// UNO TODO
// DatePickerGenerated.OnApplyTemplate();
base.OnApplyTemplate();

// Get selectors for day/month/year pickers
GetTemplatePart<Selector>("DayPicker", out spDayPicker);
Expand Down Expand Up @@ -518,7 +517,7 @@ protected override void OnApplyTemplate()

RefreshSetup();

// UpdateVisualState(false);
UpdateVisualState(false);

}
finally
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/FrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ partial void OnLoadingPartial()

// Apply active style and default style when we enter the visual tree, if they haven't been applied already.
ApplyStyles();

// This is replicating the UpdateAllThemeReferences call in Enter in WinUI.
// Updates theme references to account for new ancestor theme dictionaries.
this.UpdateResourceBindings();
}

partial void OnUnloadedPartial()
Expand Down

0 comments on commit 1ac8296

Please sign in to comment.