Skip to content

Commit

Permalink
fix: Fix x:Bind with empty path crashing when x:Load exists in the …
Browse files Browse the repository at this point in the history
…same page
  • Loading branch information
Youssef1313 committed Apr 24, 2024
1 parent 2898b5e commit 57429d0
Show file tree
Hide file tree
Showing 5 changed files with 503 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,80 @@ public MainPage()

await test.RunAsync();
}

[TestMethod]
public async Task TestPathlessXBindReferencesXLoadedElement()
{
var xamlFile = new XamlFile("MainPage.xaml", """
<Page
x:Class="TestRepro.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestRepro"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<local:NullableBoolConverter x:Key="NullableBoolConverter" />
</Page.Resources>
<StackPanel>
<ToggleButton x:Name="LoadElement" x:FieldModifier="public" x:Load="{x:Bind ToggleLoad.IsChecked, Mode=OneWay, Converter={StaticResource NullableBoolConverter}}">Loaded via x:Load and toggle enable for buttons</ToggleButton>
<Button x:Name="button1" Tag="{x:Bind}" x:FieldModifier="public">Button1</Button>
<ToggleButton x:Name="ToggleLoad" IsChecked="False" x:FieldModifier="public">Toggle Load</ToggleButton>
</StackPanel>
</Page>
""");

var test = new Verify.Test(xamlFile)
{
TestState =
{
Sources =
{
"""
using System;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
namespace TestRepro
{
internal class NullableBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null || value is bool b && b == false)
{
return false;
}
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value == null || value is bool b && b == false)
{
return false;
}
return true;
}
}
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
}
}
"""
}
}
}.AddGeneratedSources();

await test.RunAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// <autogenerated />
namespace MyProject
{
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
public sealed partial class GlobalStaticResources
{
static bool _initialized;
private static bool _stylesRegistered;
private static bool _dictionariesRegistered;
internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ { get; } = new global::Uno.UI.Xaml.XamlParseContext()
{
AssemblyName = "TestProject",
}
;

static GlobalStaticResources()
{
Initialize();
}
public static void Initialize()
{
if (!_initialized)
{
_initialized = true;
global::Uno.UI.GlobalStaticResources.Initialize();
global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles();
global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource();
}
}
public static void RegisterDefaultStyles()
{
if(!_stylesRegistered)
{
_stylesRegistered = true;
RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d();
}
}
// Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources
public static void RegisterResourceDictionariesBySource()
{
if(!_dictionariesRegistered)
{
_dictionariesRegistered = true;
}
}
// Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources
internal static void RegisterResourceDictionariesBySourceLocal()
{
}
static partial void RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// <auto-generated />
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")]
Loading

0 comments on commit 57429d0

Please sign in to comment.