From b8f127fce7807064d453ff7245ef481adba493fb Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 25 Jun 2018 00:06:40 +0200 Subject: [PATCH 1/4] Reimplemented TemplateBinding. Rather than just use a standard `Binding`, make `TemplateBinding` a lightweight binding in the case where the binding is simply to a property on the templated parent. --- samples/ControlCatalog/SideBar.xaml | 4 +- samples/RenderDemo/SideBar.xaml | 4 +- .../AutoCompleteBox.xaml | 2 +- src/Avalonia.Themes.Default/DropDown.xaml | 2 +- src/Avalonia.Themes.Default/MenuItem.xaml | 4 +- src/Avalonia.Themes.Default/ScrollBar.xaml | 4 +- src/Avalonia.Themes.Default/ScrollViewer.xaml | 10 +- src/Avalonia.Themes.Default/Slider.xaml | 7 +- src/Avalonia.Themes.Default/TabControl.xaml | 4 +- src/Avalonia.Themes.Default/TextBox.xaml | 2 +- src/Avalonia.Themes.Default/TreeViewItem.xaml | 4 +- .../AvaloniaXamlLoader.cs | 2 +- .../AvaloniaPropertyTypeConverter.cs | 89 +++++---- .../TemplateBindingExtension.cs | 42 +++-- .../PortableXaml/AvaloniaXamlSchemaContext.cs | 1 + .../PortableXaml/TypeDescriptorExtensions.cs | 8 +- .../Templates/ControlTemplate.cs | 6 +- .../Avalonia.Markup/Data/TemplateBinding.cs | 169 ++++++++++++++++++ .../AvaloniaPropertyConverterTest.cs | 13 +- .../Data/BindingTests_TemplatedParent.cs | 14 +- .../Xaml/BasicTests.cs | 2 +- 21 files changed, 285 insertions(+), 108 deletions(-) create mode 100644 src/Markup/Avalonia.Markup/Data/TemplateBinding.cs diff --git a/samples/ControlCatalog/SideBar.xaml b/samples/ControlCatalog/SideBar.xaml index e5baf9e942c..7d72d1821bd 100644 --- a/samples/ControlCatalog/SideBar.xaml +++ b/samples/ControlCatalog/SideBar.xaml @@ -8,7 +8,7 @@ + SelectedIndex="{TemplateBinding SelectedIndex, Mode=TwoWay}"> @@ -20,7 +20,7 @@ Margin="8 0 0 0" MemberSelector="{x:Static TabControl.ContentSelector}" Items="{TemplateBinding Items}" - SelectedIndex="{TemplateBinding Path=SelectedIndex}" + SelectedIndex="{TemplateBinding SelectedIndex}" PageTransition="{TemplateBinding PageTransition}" Grid.Row="1"/> diff --git a/samples/RenderDemo/SideBar.xaml b/samples/RenderDemo/SideBar.xaml index 29e5d854f94..b5f8ccaf017 100644 --- a/samples/RenderDemo/SideBar.xaml +++ b/samples/RenderDemo/SideBar.xaml @@ -9,7 +9,7 @@ + SelectedIndex="{TemplateBinding SelectedIndex, Mode=TwoWay}"> @@ -21,7 +21,7 @@ Margin="8 0 0 0" MemberSelector="{x:Static TabControl.ContentSelector}" Items="{TemplateBinding Items}" - SelectedIndex="{TemplateBinding Path=SelectedIndex}" + SelectedIndex="{TemplateBinding SelectedIndex}" PageTransition="{TemplateBinding PageTransition}" Grid.Row="1"/> diff --git a/src/Avalonia.Themes.Default/AutoCompleteBox.xaml b/src/Avalonia.Themes.Default/AutoCompleteBox.xaml index 82dbf6064bd..6a9af487cba 100644 --- a/src/Avalonia.Themes.Default/AutoCompleteBox.xaml +++ b/src/Avalonia.Themes.Default/AutoCompleteBox.xaml @@ -16,7 +16,7 @@ DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}" /> diff --git a/src/Avalonia.Themes.Default/DropDown.xaml b/src/Avalonia.Themes.Default/DropDown.xaml index 139b2b3687d..c57d961f4ba 100644 --- a/src/Avalonia.Themes.Default/DropDown.xaml +++ b/src/Avalonia.Themes.Default/DropDown.xaml @@ -32,7 +32,7 @@ diff --git a/src/Avalonia.Themes.Default/MenuItem.xaml b/src/Avalonia.Themes.Default/MenuItem.xaml index efb31175fa2..53965db016a 100644 --- a/src/Avalonia.Themes.Default/MenuItem.xaml +++ b/src/Avalonia.Themes.Default/MenuItem.xaml @@ -45,7 +45,7 @@ @@ -67,7 +67,7 @@ Grid.Column="1" Minimum="{TemplateBinding Minimum}" Maximum="{TemplateBinding Maximum}" - Value="{TemplateBinding Path=Value, Mode=TwoWay}" + Value="{TemplateBinding Value, Mode=TwoWay}" ViewportSize="{TemplateBinding ViewportSize}" Orientation="{TemplateBinding Orientation}"> diff --git a/src/Avalonia.Themes.Default/ScrollViewer.xaml b/src/Avalonia.Themes.Default/ScrollViewer.xaml index 5355d5c7c30..c493fb32e3f 100644 --- a/src/Avalonia.Themes.Default/ScrollViewer.xaml +++ b/src/Avalonia.Themes.Default/ScrollViewer.xaml @@ -9,21 +9,21 @@ CanHorizontallyScroll="{TemplateBinding CanHorizontallyScroll}" CanVerticallyScroll="{TemplateBinding CanVerticallyScroll}" Content="{TemplateBinding Content}" - Extent="{TemplateBinding Path=Extent, Mode=TwoWay}" + Extent="{TemplateBinding Extent, Mode=TwoWay}" Margin="{TemplateBinding Padding}" - Offset="{TemplateBinding Path=Offset, Mode=TwoWay}" - Viewport="{TemplateBinding Path=Viewport, Mode=TwoWay}"/> + Offset="{TemplateBinding Offset, Mode=TwoWay}" + Viewport="{TemplateBinding Viewport, Mode=TwoWay}"/> diff --git a/src/Avalonia.Themes.Default/Slider.xaml b/src/Avalonia.Themes.Default/Slider.xaml index 09446124171..58fd67b2f65 100644 --- a/src/Avalonia.Themes.Default/Slider.xaml +++ b/src/Avalonia.Themes.Default/Slider.xaml @@ -11,7 +11,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -72,8 +72,7 @@