Browse Source

Merge pull request #7388 from AvaloniaUI/compiledbindings-themes

Use CompiledBindings for Fluent theme
Max Katz 3 years ago
parent
commit
1d44558d4e

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml

@@ -1,7 +1,8 @@
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:sys="clr-namespace:System;assembly=netstandard"
-        xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls">
+        xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20"
             Background="Black">

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/CalendarDatePicker.xaml

@@ -7,7 +7,8 @@
 
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:sys="clr-namespace:System;assembly=netstandard">
+        xmlns:sys="clr-namespace:System;assembly=netstandard"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Margin="20, 20, 20, 200">
       <CalendarDatePicker Width="200"

+ 3 - 1
src/Avalonia.Themes.Fluent/Controls/CalendarItem.xaml

@@ -6,7 +6,9 @@
 -->
 
 <Styles xmlns="https://github.com/avaloniaui"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:CompileBindings="True"
+        x:DataType="CalendarItem">
   <Design.PreviewWith>
     <Border Padding="20">
       <Calendar />

+ 5 - 3
src/Avalonia.Themes.Fluent/Controls/DataValidationErrors.xaml

@@ -1,6 +1,8 @@
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:sys="using:System">
+        xmlns:sys="using:System"
+        x:CompileBindings="True"
+        x:DataType="DataValidationErrors">
   <Design.PreviewWith>
     <Border Padding="20">
       <StackPanel Spacing="20">
@@ -27,7 +29,7 @@
   <Style Selector="DataValidationErrors">
     <Style.Resources>
       <DataTemplate x:Key="InlineDataValidationErrorTemplate">
-        <ItemsControl Items="{Binding}" TextBlock.Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}">
+        <ItemsControl Items="{Binding}" x:DataType="DataValidationErrors" TextBlock.Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}">
           <ItemsControl.Styles>
             <Style Selector="TextBlock">
               <Setter Property="TextWrapping" Value="Wrap" />
@@ -54,7 +56,7 @@
         </DockPanel>
       </ControlTemplate>
 
-      <DataTemplate x:Key="TooltipDataValidationErrorTemplate">
+      <DataTemplate x:DataType="DataValidationErrors" x:Key="TooltipDataValidationErrorTemplate">
         <Panel Name="PART_InlineErrorTemplatePanel" Background="Transparent">
           <Panel.Styles>
             <Style Selector="Panel#PART_InlineErrorTemplatePanel">

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/DatePicker.xaml

@@ -7,7 +7,8 @@
 
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:sys="clr-namespace:System;assembly=netstandard">
+        xmlns:sys="clr-namespace:System;assembly=netstandard"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20">
       <DatePicker CornerRadius="10" />

+ 5 - 3
src/Avalonia.Themes.Fluent/Controls/Expander.xaml

@@ -1,4 +1,6 @@
-<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+<Styles xmlns="https://github.com/avaloniaui" 
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20">
       <StackPanel Orientation="Vertical" Spacing="20" Width="350">
@@ -69,13 +71,13 @@
                         BorderThickness="{TemplateBinding BorderThickness}"
                         Content="{TemplateBinding Header}"
                         ContentTemplate="{TemplateBinding HeaderTemplate}"
-                        IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
+                        IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}"
                         IsEnabled="{TemplateBinding IsEnabled}" />
           <Border x:Name="ExpanderContent"
                   Padding="{DynamicResource ExpanderContentPadding}"
                   Background="{DynamicResource ExpanderDropDownBackground}"
                   BorderBrush="{DynamicResource ExpanderDropDownBorderBrush}"
-                  IsVisible="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
+                  IsVisible="{TemplateBinding IsExpanded, Mode=TwoWay}">
             <ContentPresenter x:Name="PART_ContentPresenter"
                               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                               VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"

+ 2 - 2
src/Avalonia.Themes.Fluent/Controls/ManagedFileChooser.xaml

@@ -142,7 +142,7 @@
                         <Rectangle Fill="{DynamicResource SystemControlHighlightAltBaseMediumLowBrush}" Height="1" Margin="0,5,0,0" DockPanel.Dock="Bottom"/>
                         <DockPanel Margin="4,0">
                             <Button Command="{Binding GoUp}" DockPanel.Dock="Left">
-                                <Path Data="M 0 7 L 7 0 L 14 7 M 7 0 L 7 16" Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,1,0,-1"/>
+                                <Path Data="M 0 7 L 7 0 L 14 7 M 7 0 L 7 16" Stroke="{CompiledBinding $parent[Button].Foreground}" StrokeThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,1,0,-1"/>
                             </Button>
                             <TextBox x:Name="Location" Text="{Binding Location}">
                                 <TextBox.KeyBindings>
@@ -321,4 +321,4 @@
     <Style Selector="dialogs|ManagedFileChooser /template/ UniformGrid#Finalize > Button /template/ ContentPresenter#PART_ContentPresenter">
             <Setter Property="HorizontalAlignment" Value="Stretch"/>
     </Style>
-</Styles>
+</Styles>

+ 4 - 2
src/Avalonia.Themes.Fluent/Controls/MenuItem.xaml

@@ -1,7 +1,9 @@
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:conv="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
-        xmlns:sys="clr-namespace:System;assembly=netstandard">
+        xmlns:sys="clr-namespace:System;assembly=netstandard"
+        x:DataType="MenuItem"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20"
             Width="400"
@@ -158,7 +160,7 @@
             </ContentPresenter>
             <Popup Name="PART_Popup"
                    WindowManagerAddShadowHint="False"
-                   MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
+                   MinWidth="{ReflectionBinding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
                    IsLightDismissEnabled="True"
                    IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}"
                    OverlayInputPassThroughElement="{Binding $parent[Menu]}">

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml

@@ -1,6 +1,7 @@
 <Style xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Avalonia.Themes.Fluent"
+       x:CompileBindings="True"
        Selector="NativeMenuBar">
   <Style.Resources>
     <local:InverseBooleanValueConverter x:Key="AvaloniaThemesDefaultNativeMenuBarInverseBooleanValueConverter" Default="True"/>
@@ -11,7 +12,7 @@
         IsVisible="{Binding $parent[TopLevel].(NativeMenu.IsNativeMenuExported), Converter={StaticResource AvaloniaThemesDefaultNativeMenuBarInverseBooleanValueConverter}}"
         Items="{Binding $parent[TopLevel].(NativeMenu.Menu).Items}">
         <Menu.Styles>
-          <Style Selector="MenuItem">
+          <Style x:DataType="NativeMenuItem" Selector="MenuItem">
             <Setter Property="Header" Value="{Binding Header}"/>
             <Setter Property="InputGesture" Value="{Binding Gesture}"/>
             <Setter Property="Items" Value="{Binding Menu.Items}"/>

+ 5 - 3
src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml

@@ -1,4 +1,6 @@
-<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+<Styles xmlns="https://github.com/avaloniaui" 
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20">
       <StackPanel Spacing="10">
@@ -29,8 +31,8 @@
                 <Border x:Name="IndeterminateProgressBarIndicator" CornerRadius="{TemplateBinding CornerRadius}" Margin="{TemplateBinding Padding}" Background="{TemplateBinding Foreground}" />
                 <Border x:Name="IndeterminateProgressBarIndicator2" CornerRadius="{TemplateBinding CornerRadius}" Margin="{TemplateBinding Padding}" Background="{TemplateBinding Foreground}" />
               </Panel>
-              <LayoutTransformControl x:Name="PART_LayoutTransformControl" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="{Binding ShowProgressText, RelativeSource={RelativeSource TemplatedParent}}">
-                <TextBlock Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, StringFormat={}{0:0}%}" />
+              <LayoutTransformControl x:Name="PART_LayoutTransformControl" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="{TemplateBinding ShowProgressText}">
+                <TextBlock Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" Text="{ReflectionBinding Value, RelativeSource={RelativeSource TemplatedParent}, StringFormat={}{0:0}%}" />
               </LayoutTransformControl>
             </Panel>
         </Border>

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/TabItem.xaml

@@ -1,5 +1,6 @@
 <Styles xmlns="https://github.com/avaloniaui"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20">
       <StackPanel Spacing="20">

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/TabStripItem.xaml

@@ -1,5 +1,6 @@
 <Styles xmlns="https://github.com/avaloniaui"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:CompileBindings="True">
   <Design.PreviewWith>
     <Border Padding="20">
       <StackPanel Spacing="20">

+ 1 - 1
src/Avalonia.Themes.Fluent/Controls/TextBox.xaml

@@ -166,7 +166,7 @@
     <Setter Property="InnerRightContent">
       <Template>
         <ToggleButton Classes="passwordBoxRevealButton"
-                      IsChecked="{Binding $parent[TextBox].RevealPassword, Mode=TwoWay}" />
+                      IsChecked="{CompiledBinding $parent[TextBox].RevealPassword, Mode=TwoWay}" />
       </Template>
     </Setter>
   </Style>

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/TimePicker.xaml

@@ -7,7 +7,8 @@
 
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:sys="clr-namespace:System;assembly=netstandard">
+        xmlns:sys="clr-namespace:System;assembly=netstandard"
+        x:CompileBindings="True">
   <Styles.Resources>
     <x:Double x:Key="TimePickerFlyoutPresenterItemHeight">40</x:Double>
     <x:Double x:Key="TimePickerSpacerThemeWidth">1</x:Double>

+ 2 - 1
src/Avalonia.Themes.Fluent/Controls/ToolTip.xaml

@@ -1,6 +1,7 @@
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       
-        xmlns:sys="clr-namespace:System;assembly=netstandard">
+        xmlns:sys="clr-namespace:System;assembly=netstandard"
+        x:CompileBindings="True">
 
   <Design.PreviewWith>
     <Grid RowDefinitions="Auto,Auto"

+ 3 - 1
src/Avalonia.Themes.Fluent/Controls/WindowNotificationManager.xaml

@@ -1,5 +1,7 @@
 <Styles xmlns="https://github.com/avaloniaui"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:DataType="WindowNotificationManager"
+        x:CompileBindings="True">
   <Style Selector="WindowNotificationManager">
     <Setter Property="Margin" Value="0 0"/>    
     <Setter Property="Template">