-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
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
- Loading branch information
1 parent
efa6b97
commit b87a3c2
Showing
6 changed files
with
126 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,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); | ||
} | ||
} | ||
} |