-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[X] allow namescope resolution before parenting (#22854)
* [X] allow namescope resolution before parenting when an element doesn't override the NameScope (DataTemplate, etc...) FindName fails until the element is parented. this PR sets a field (less expensive than a BP) used only during that time, and allow VSM to be applied. - fixes #22001 * fix * fixes #16208
- Loading branch information
1 parent
6d1f2a4
commit 87253a5
Showing
8 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui16208"> | ||
<HorizontalStackLayout x:Name="ItemHorizontalStack" HorizontalOptions="Center" VerticalOptions="Center" Padding="20"> | ||
<Label x:Name="ItemLabel" | ||
Text="This is the label inside" | ||
FontSize="18" /> | ||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroupList> | ||
<VisualStateGroup x:Name="CommonStates"> | ||
<VisualState x:Name="Normal"> | ||
<VisualState.Setters> | ||
<Setter Property="BackgroundColor" Value="Red" /> | ||
<Setter TargetName="ItemLabel" Property="Label.BackgroundColor" Value="Green" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
|
||
<VisualState x:Name="PointerOver"> | ||
<VisualState.Setters> | ||
<Setter Property="BackgroundColor" Value="Yellow" /> | ||
<Setter TargetName="ItemLabel" Property="Label.BackgroundColor" Value="Black" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateGroupList> | ||
</VisualStateManager.VisualStateGroups> | ||
</HorizontalStackLayout> | ||
|
||
</ContentPage> |
59 changes: 59 additions & 0 deletions
59
src/Controls/tests/Xaml.UnitTests/Issues/Maui16208.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Controls.Shapes; | ||
using Microsoft.Maui.Devices; | ||
using Microsoft.Maui.Dispatching; | ||
|
||
using Microsoft.Maui.Graphics; | ||
using Microsoft.Maui.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui16208 | ||
{ | ||
public Maui16208() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public Maui16208(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
[TestFixture] | ||
class Test | ||
{ | ||
MockDeviceInfo mockDeviceInfo; | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Application.SetCurrentApplication(new MockApplication()); | ||
DispatcherProvider.SetCurrent(new DispatcherProviderStub()); | ||
|
||
DeviceInfo.SetCurrent(mockDeviceInfo = new MockDeviceInfo()); | ||
} | ||
|
||
[TearDown] public void TearDown() | ||
{ | ||
AppInfo.SetCurrent(null); | ||
mockDeviceInfo = null; | ||
} | ||
|
||
[Test] | ||
public void SetterAndTargetName([Values(false, true)] bool useCompiledXaml) | ||
{ | ||
|
||
Assert.DoesNotThrow(() => new Maui16208(useCompiledXaml)); | ||
var page = new Maui16208(useCompiledXaml); | ||
Assert.That(page!.ItemLabel.BackgroundColor, Is.EqualTo(Colors.Green)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui22001"> | ||
|
||
<Grid> | ||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroupList> | ||
<VisualStateGroup> | ||
<VisualState x:Name="Portrait"> | ||
<VisualState.StateTriggers> | ||
<OrientationStateTrigger Orientation="Portrait" /> | ||
</VisualState.StateTriggers> | ||
<VisualState.Setters> | ||
<Setter Property="Grid.IsVisible" TargetName="_firstGrid" Value="true"/> | ||
<Setter Property="Grid.IsVisible" TargetName="_secondGrid" Value="false"/> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="Landscape"> | ||
<VisualState.StateTriggers> | ||
<OrientationStateTrigger Orientation="Landscape" /> | ||
</VisualState.StateTriggers> | ||
<VisualState.Setters> | ||
<Setter Property="Grid.IsVisible" TargetName="_firstGrid" Value="false"/> | ||
<Setter Property="Grid.IsVisible" TargetName="_secondGrid" Value="true"/> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateGroupList> | ||
</VisualStateManager.VisualStateGroups> | ||
<Grid x:Name="_firstGrid" HeightRequest="200" BackgroundColor="Yellow" /> | ||
<Grid x:Name="_secondGrid" HeightRequest="200" BackgroundColor="Red"/> | ||
</Grid> | ||
</ContentPage> |
70 changes: 70 additions & 0 deletions
70
src/Controls/tests/Xaml.UnitTests/Issues/Maui22001.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.ApplicationModel; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Controls.Shapes; | ||
using Microsoft.Maui.Devices; | ||
using Microsoft.Maui.Dispatching; | ||
|
||
using Microsoft.Maui.Graphics; | ||
using Microsoft.Maui.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
||
public partial class Maui22001 | ||
{ | ||
public Maui22001() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public Maui22001(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
[TestFixture] | ||
class Test | ||
{ | ||
MockDeviceDisplay mockDeviceDisplay; | ||
MockDeviceInfo mockDeviceInfo; | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Application.SetCurrentApplication(new MockApplication()); | ||
DispatcherProvider.SetCurrent(new DispatcherProviderStub()); | ||
|
||
DeviceDisplay.SetCurrent(mockDeviceDisplay = new MockDeviceDisplay()); | ||
DeviceInfo.SetCurrent(mockDeviceInfo = new MockDeviceInfo()); | ||
} | ||
|
||
[TearDown] public void TearDown() | ||
{ | ||
AppInfo.SetCurrent(null); | ||
mockDeviceDisplay = null; | ||
mockDeviceInfo = null; | ||
} | ||
|
||
[Test] | ||
public void StateTriggerTargetName([Values(false, true)] bool useCompiledXaml) | ||
{ | ||
var page = new Maui22001(useCompiledXaml); | ||
|
||
IWindow window = new Window | ||
{ | ||
Page = page | ||
}; | ||
Assert.That(page._firstGrid.IsVisible, Is.True); | ||
Assert.That(page._secondGrid.IsVisible, Is.False); | ||
|
||
mockDeviceDisplay.SetMainDisplayOrientation(DisplayOrientation.Landscape); | ||
Assert.That(page._firstGrid.IsVisible, Is.False); | ||
Assert.That(page._secondGrid.IsVisible, Is.True); | ||
} | ||
} | ||
} |