Skip to content

Commit

Permalink
feat(xLoad): Add xLoad binding capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Feb 1, 2021
1 parent 017cdce commit e2868b0
Show file tree
Hide file tree
Showing 32 changed files with 844 additions and 123 deletions.
6 changes: 6 additions & 0 deletions doc/articles/features/windows-ui-xaml-xbind.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ Uno supports the [`x:Bind`](https://docs.microsoft.com/en-us/windows/uwp/xaml-pl
```xaml
<TextBox FontFamily="{x:Bind (FontFamily)MyComboBox.SelectedValue}" />
```

- `x:Load` binding
```xaml
<TextBox x:Load="{x:Bind IsMyControlVisible}" />
```
See the [WinUI documentation](https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-load-attribute) for more details.
2 changes: 1 addition & 1 deletion doc/articles/supported-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
### Runtime Performance

- CoreDispatcher Priority support (Large UIs performance)
- `x:DeferLoadStrategy="Lazy"` and `x:Load="false"` support (responsive design performance)
- `x:DeferLoadStrategy="Lazy"`, `x:Load="false"` and `x:Load="{x:Bind ...}" support (responsive design performance)
- Image explicit size support (performance)
- Event tracing (sub-millisecond [ETL performance profiling](Assets/diagnostics.PNG))
- Internal logging
Expand Down
28 changes: 28 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,22 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_FindName.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_Literal.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_Test_For_Leak.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_xBind.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BitmapIconTests\BitmapIcon_Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -4368,6 +4384,18 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xBindTests\xBind_Functions.xaml.cs">
<DependentUpon>xBind_Functions.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_FindName.xaml.cs">
<DependentUpon>xLoad_FindName.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_Literal.xaml.cs">
<DependentUpon>xLoad_Literal.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_Test_For_Leak.xaml.cs">
<DependentUpon>xLoad_Test_For_Leak.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\xLoadTests\xLoad_xBind.xaml.cs">
<DependentUpon>xLoad_xBind.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BorderTests\Border_Clipped_Change_Property.xaml.cs">
<DependentUpon>Border_Clipped_Change_Property.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<UserControl
x:Class="UITests.Windows_UI_Xaml.xLoadTests.xLoad_FindName"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml.xLoadTests"
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">

<StackPanel>
<TextBlock Text="Clicking on the Load button should make a Green box appear in the Red border"/>
<Button Content="Load" x:Name="LoadButton"/>
<Border BorderBrush="Red" BorderThickness="1" Width="60" Height="60">
<Border x:Name="LoadBorder" Width="50" Height="50" Background="Green" x:Load="False"/>
</Border>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
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;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Windows_UI_Xaml.xLoadTests
{
[Sample("xLoad", Name = "xLoad_FindName")]
public sealed partial class xLoad_FindName : UserControl
{
public xLoad_FindName()
{
this.InitializeComponent();
LoadButton.Click += LoadButton_Click;
}

private void LoadButton_Click(object sender, RoutedEventArgs e)
{
FindName("LoadBorder");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<UserControl
x:Class="UITests.Windows_UI_Xaml.xLoadTests.xLoad_Literal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml.xLoadTests"
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">

<StackPanel>
<TextBlock Text="Should see two Red borders, the top one should be empty, the bottom one should contain a Green box"/>
<TextBlock Margin="0, 10, 0, 0" Text="Load = False" HorizontalAlignment="Center"/>
<Border BorderBrush="Red" BorderThickness="1" Width="60" Height="60">
<Border x:Name="LoadBorderFalse" Width="50" Height="50" Background="Green" x:Load="False"/>
</Border>
<TextBlock Margin="0, 10, 0, 0" Text="Load = True" HorizontalAlignment="Center"/>
<Border BorderBrush="Red" BorderThickness="1" Width="60" Height="60">
<Border x:Name="LoadBorderTrue" Width="50" Height="50" Background="Green" x:Load="True"/>
</Border>
</StackPanel>
</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 Uno.UI.Samples.Controls;
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;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Windows_UI_Xaml.xLoadTests
{
[Sample("xLoad", Name = "xLoad_Literal")]
public sealed partial class xLoad_Literal : UserControl
{
public xLoad_Literal()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<UserControl
x:Class="UITests.Windows_UI_Xaml.xLoadTests.xLoad_Test_For_Leak"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml.xLoadTests"
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>
<Border x:Name="outerBorder" BorderBrush="Red" BorderThickness="1" Width="60" Height="60">
<Border x:Name="LoadBorder" Width="50" Height="50" Background="Green" x:Load="{x:Bind IsLoad, Mode=OneWay}" />
</Border>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
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;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Windows_UI_Xaml.xLoadTests
{
[Sample("xLoad", Name = "xLoad_Test_For_Leak")]
public sealed partial class xLoad_Test_For_Leak : UserControl
{
public bool IsLoad
{
get { return (bool)GetValue(IsLoadProperty); }
set { SetValue(IsLoadProperty, value); }
}

// Using a DependencyProperty as the backing store for IsLoad. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsLoadProperty =
DependencyProperty.Register("IsLoad", typeof(bool), typeof(xLoad_Test_For_Leak), new PropertyMetadata(false));

public xLoad_Test_For_Leak()
{
this.InitializeComponent();

IsLoad = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<UserControl
x:Class="UITests.Windows_UI_Xaml.xLoadTests.xLoad_xBind"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml.xLoadTests"
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">

<StackPanel>
<CheckBox Content="Is Loaded" x:Name="LoadCheckBox" Margin="30" IsChecked="{x:Bind IsLoad, Mode=TwoWay}" />
<Border BorderBrush="Red" BorderThickness="1" Width="60" Height="60">
<Border x:Name="LoadBorder" Width="50" Height="50" Background="Green" x:Load="{x:Bind IsLoad, Mode=OneWay}" />
</Border>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
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;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Windows_UI_Xaml.xLoadTests
{
[Sample("xLoad", Name = "xLoad_xBind")]
public sealed partial class xLoad_xBind : UserControl
{
public bool IsLoad
{
get { return (bool)GetValue(IsLoadProperty); }
set { SetValue(IsLoadProperty, value); }
}

// Using a DependencyProperty as the backing store for IsLoad. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsLoadProperty =
DependencyProperty.Register("IsLoad", typeof(bool), typeof(xLoad_xBind), new PropertyMetadata(false));

public xLoad_xBind()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
{
internal class NameScope
{
public NameScope(string name)
public NameScope(string @namespace, string className)
{
this.Name = name;
Namespace = @namespace ?? string.Empty;
ClassName = className;
}

public string Name { get; private set; }
public string Name => $"{Namespace.Replace(".", "")}{ClassName}";
public string Namespace { get; private set; }
public string ClassName { get; private set; }

public List<BackingFieldDefinition> BackingFields { get; } = new List<BackingFieldDefinition>();

/// <summary>
/// Lists the ElementStub builder holder variables used to pin references for implicit pinning platforms
/// </summary>
public List<string> ElementStubHolders { get; } = new List<string>();

public HashSet<string> ReferencedElementNames { get; } = new HashSet<string>();

public Dictionary<string, Subclass> Subclasses { get; } = new Dictionary<string, Subclass>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,22 @@ private bool IsFrameworkElement(XamlType xamlType)

private bool IsDependencyObject(XamlType xamlType)
{
return IsType(xamlType, XamlConstants.Types.DependencyObject);
return IsType(xamlType, _dependencyObjectSymbol);
}

private bool IsAndroidView(XamlType xamlType)
{
return IsType(xamlType, "Android.Views.View");
return IsType(xamlType, _androidViewSymbol);
}

private bool IsIOSUIView(XamlType xamlType)
{
return IsType(xamlType, "UIKit.UIView");
return IsType(xamlType, _iOSViewSymbol);
}

private bool IsMacOSNSView(XamlType xamlType)
{
return IsType(xamlType, "AppKit.NSView");
return IsType(xamlType, _appKitViewSymbol);
}

/// <summary>
Expand Down
Loading

0 comments on commit e2868b0

Please sign in to comment.