Merge remote-tracking branch 'origin/feature/compiled-bindings' into feature/avalonia-preview7

This commit is contained in:
Robert committed 2023-05-06 13:12:07 +02:00
commit 2e88b438f0
65 files changed
+415 -298

No files matched your search

@@ -1,4 +1,4 @@
<UserControl xmlns="https://github.com/avaloniaui"
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -25,14 +25,14 @@
<Panel>
<controls:NumberBox Name="InnerNumberBox"
AcceptsExpression="True"
LargeChange="{Binding $parent[sharedControls:DraggableNumberBox].LargeChange}"
SmallChange="{Binding $parent[sharedControls:DraggableNumberBox].SmallChange}"
Minimum="{Binding $parent[sharedControls:DraggableNumberBox].Minimum}"
Maximum="{Binding $parent[sharedControls:DraggableNumberBox].Maximum}"
SimpleNumberFormat="{Binding $parent[sharedControls:DraggableNumberBox].SimpleNumberFormat}"
attachedProperties:NumberBoxAssist.PrefixText="{Binding $parent[sharedControls:DraggableNumberBox].Prefix}"
attachedProperties:NumberBoxAssist.SuffixText="{Binding $parent[sharedControls:DraggableNumberBox].Suffix}"
HorizontalAlignment="{Binding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}"
LargeChange="{CompiledBinding $parent[sharedControls:DraggableNumberBox].LargeChange}"
SmallChange="{CompiledBinding $parent[sharedControls:DraggableNumberBox].SmallChange}"
Minimum="{CompiledBinding $parent[sharedControls:DraggableNumberBox].Minimum}"
Maximum="{CompiledBinding $parent[sharedControls:DraggableNumberBox].Maximum}"
SimpleNumberFormat="{CompiledBinding $parent[sharedControls:DraggableNumberBox].SimpleNumberFormat}"
attachedProperties:NumberBoxAssist.PrefixText="{CompiledBinding $parent[sharedControls:DraggableNumberBox].Prefix}"
attachedProperties:NumberBoxAssist.SuffixText="{CompiledBinding $parent[sharedControls:DraggableNumberBox].Suffix}"
HorizontalAlignment="{CompiledBinding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}"
ValueChanged="NumberBox_OnValueChanged"/>
<Rectangle Name="DragCollider" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="Transparent"></Rectangle>
</Panel>
@@ -3,11 +3,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:local="clr-namespace:Artemis.UI.Shared"
x:Class="Artemis.UI.Shared.EnumComboBox">
<ComboBox x:Name="ChildEnumComboBox" HorizontalAlignment="Stretch">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding [1]}" />
<DataTemplate x:DataType="local:EnumComboBoxItem">
<TextBlock Text="{CompiledBinding Value}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
@@ -20,11 +20,9 @@ public partial class EnumComboBox : UserControl
/// </summary>
public static readonly StyledProperty<object?> ValueProperty = AvaloniaProperty.Register<EnumComboBox, object?>(nameof(Value), defaultBindingMode: BindingMode.TwoWay);
private readonly ObservableCollection<(Enum, string)> _currentValues = new();
private readonly ObservableCollection<EnumComboBoxItem> _currentValues = new();
private Type? _currentType;
private ComboBox? _enumComboBox;
/// <summary>
/// Creates a new instance of the <see cref="EnumComboBox" /> class.
/// </summary>
@@ -54,35 +52,35 @@ public partial class EnumComboBox : UserControl
private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (_enumComboBox == null || _enumComboBox.SelectedIndex == -1)
if (ChildEnumComboBox == null || ChildEnumComboBox.SelectedIndex == -1)
return;
(Enum enumValue, _) = _currentValues[_enumComboBox.SelectedIndex];
if (!Equals(Value, enumValue))
Value = enumValue;
EnumComboBoxItem v = _currentValues[ChildEnumComboBox.SelectedIndex];
if (!Equals(Value, v.Value))
Value = v.Value;
}
private void UpdateValues()
{
Type? newType = Value?.GetType();
if (_enumComboBox == null || newType == null || _currentType == newType)
if (ChildEnumComboBox == null || newType == null || _currentType == newType)
return;
_currentValues.Clear();
foreach ((Enum, string) valueDesc in EnumUtilities.GetAllValuesAndDescriptions(newType))
_currentValues.Add(valueDesc);
_currentValues.Add(new EnumComboBoxItem(value: valueDesc.Item1, description: valueDesc.Item2));
_currentType = newType;
}
private void UpdateSelection()
{
if (_enumComboBox == null || Value is not Enum)
if (ChildEnumComboBox == null || Value is not Enum)
return;
(Enum, string) value = _currentValues.FirstOrDefault(v => v.Item1.Equals(Value));
if (!Equals(value.Item1, _enumComboBox.SelectedItem))
_enumComboBox.SelectedItem = value;
EnumComboBoxItem? value = _currentValues.FirstOrDefault(v => v.Value.Equals(Value));
if (!Equals(value?.Value, ChildEnumComboBox.SelectedItem))
ChildEnumComboBox.SelectedItem = value;
}
#region Overrides of TemplatedControl
@@ -90,12 +88,11 @@ public partial class EnumComboBox : UserControl
/// <inheritdoc />
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
_enumComboBox = this.Get<ComboBox>("ChildEnumComboBox");
_enumComboBox.ItemsSource = _currentValues;
ChildEnumComboBox.ItemsSource = _currentValues;
UpdateValues();
UpdateSelection();
_enumComboBox.SelectionChanged += OnSelectionChanged;
ChildEnumComboBox.SelectionChanged += OnSelectionChanged;
base.OnAttachedToLogicalTree(e);
}
@@ -103,11 +100,36 @@ public partial class EnumComboBox : UserControl
/// <inheritdoc />
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
if (_enumComboBox != null)
_enumComboBox.SelectionChanged -= OnSelectionChanged;
if (ChildEnumComboBox != null)
ChildEnumComboBox.SelectionChanged -= OnSelectionChanged;
base.OnDetachedFromLogicalTree(e);
}
#endregion
}
/// <summary>
/// Represents an item in the <see cref="EnumComboBox" />
/// </summary>
public class EnumComboBoxItem
{
/// <summary>
/// Creates a new instance of the <see cref="EnumComboBoxItem" /> class.
/// </summary>
public EnumComboBoxItem(Enum value, string description)
{
Value = value;
Description = description;
}
/// <summary>
/// Gets or sets the value of the item
/// </summary>
public Enum Value { get; set; }
/// <summary>
/// Gets or sets the description of the item
/// </summary>
public string Description { get; set; }
}
@@ -26,8 +26,8 @@
</UserControl.Styles>
<shared:NoInputTextBox x:Name="DisplayTextBox"
Watermark="{Binding $parent.Watermark}"
UseFloatingWatermark="{Binding $parent.UseFloatingWatermark}"
Watermark="{CompiledBinding $parent.Watermark}"
UseFloatingWatermark="{CompiledBinding $parent.UseFloatingWatermark}"
Classes="clearButton"
IsReadOnly="True"
HorizontalAlignment="Stretch" />
@@ -35,6 +35,7 @@ public partial class HotkeyBox : UserControl
UpdateDisplayTextBox();
}
/// <inheritdoc />
protected override void OnGotFocus(GotFocusEventArgs e)
{
_inputService.KeyboardKeyDown += InputServiceOnKeyboardKeyDown;
@@ -43,6 +44,7 @@ public partial class HotkeyBox : UserControl
base.OnGotFocus(e);
}
/// <inheritdoc />
protected override void OnLostFocus(RoutedEventArgs e)
{
_inputService.KeyboardKeyDown -= InputServiceOnKeyboardKeyDown;
@@ -3,22 +3,24 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:local="clr-namespace:Artemis.UI.Shared.DefaultTypes.DataModel.Display"
x:DataType="local:DefaultDataModelDisplayViewModel"
x:Class="Artemis.UI.Shared.DefaultTypes.DataModel.Display.DefaultDataModelDisplayView">
<Grid ColumnDefinitions="*,Auto,Auto">
<!-- Prefix -->
<TextBlock Grid.Column="0"
Text="{Binding PropertyDescription.Prefix}"
IsVisible="{Binding PropertyDescription.Prefix, Converter={x:Static ObjectConverters.IsNotNull}}"
Text="{CompiledBinding PropertyDescription.Prefix}"
IsVisible="{CompiledBinding PropertyDescription.Prefix, Converter={x:Static ObjectConverters.IsNotNull}}"
TextAlignment="Right"
Margin="0 0 5 0" />
<!-- Value -->
<TextBlock Grid.Column="1" Text="{Binding Display, Mode=OneWay}" HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1" Text="{CompiledBinding Display, Mode=OneWay}" HorizontalAlignment="Right"/>
<!-- Affix -->
<TextBlock Grid.Column="2"
Text="{Binding PropertyDescription.Affix}"
IsVisible="{Binding PropertyDescription.Affix, Converter={x:Static ObjectConverters.IsNotNull}}"
Text="{CompiledBinding PropertyDescription.Affix}"
IsVisible="{CompiledBinding PropertyDescription.Affix, Converter={x:Static ObjectConverters.IsNotNull}}"
Margin="5 0 0 0" />
</Grid>
</UserControl>
@@ -2,9 +2,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Artemis.UI.Shared.Services"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="800"
x:Class="Artemis.UI.Shared.Services.ExceptionDialogView"
Title="{Binding Title}"
x:DataType="local:ExceptionDialogViewModel"
Title="{CompiledBinding Title}"
ExtendClientAreaToDecorationsHint="True"
Width="800"
Height="800"
@@ -16,7 +18,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Margin="10" Grid.Row="1" IsHitTestVisible="False" Text="{Binding Title}" />
<TextBlock Margin="10" Grid.Row="1" IsHitTestVisible="False" Text="{CompiledBinding Title}" />
<StackPanel Grid.Row="2" Margin="20">
<TextBlock Classes="h3">Awww :(</TextBlock>
@@ -27,7 +29,7 @@
<Grid Grid.Row="3" ColumnDefinitions="*,Auto" RowDefinitions="*,Auto">
<ScrollViewer Grid.Row="0" Grid.ColumnSpan="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="20 0">
<TextBox Text="{Binding Exception, Mode=OneTime}"
<TextBox Text="{CompiledBinding Exception, Mode=OneTime}"
AcceptsReturn="True"
IsReadOnly="True"
FontFamily="Consolas"
@@ -39,10 +41,10 @@
When reporting errors please don't take a screenshot of the error, instead copy the text, thanks!
</TextBlock>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="15">
<Button Command="{Binding CopyException}" Classes="AppBarButton" Width="150" Margin="0 0 5 0">
<Button Command="{CompiledBinding CopyException}" Classes="AppBarButton" Width="150" Margin="0 0 5 0">
Copy exception
</Button>
<Button Command="{Binding Close}" Width="150" Margin="5 0 0 0">
<Button Command="{CompiledBinding Close}" Width="150" Margin="5 0 0 0">
Close
</Button>
</StackPanel>
@@ -19,7 +19,7 @@
<Grid ColumnDefinitions="Auto,*"
RowDefinitions="*"
MinHeight="38"
IsVisible="{Binding DataModelPath, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNotNull}}">
IsVisible="{CompiledBinding DataModelPath, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNotNull}}">
<avalonia:MaterialIcon Grid.Column="0"
Grid.Row="0"
Name="CurrentPathIcon"
@@ -27,7 +27,7 @@
Height="22"
Width="22"
Margin="5 0 15 0"
IsVisible="{Binding !IsEventPicker, RelativeSource={RelativeSource TemplatedParent}}"/>
IsVisible="{CompiledBinding !IsEventPicker, RelativeSource={RelativeSource TemplatedParent}}"/>
<avalonia:MaterialIcon Grid.Column="0"
Grid.Row="0"
Name="EventIcon"
@@ -35,14 +35,14 @@
Height="22"
Width="22"
Margin="5 0 15 0"
IsVisible="{Binding IsEventPicker, RelativeSource={RelativeSource TemplatedParent}}"/>
IsVisible="{CompiledBinding IsEventPicker, RelativeSource={RelativeSource TemplatedParent}}"/>
<StackPanel Grid.Column="1" Grid.Row="0" VerticalAlignment="Center">
<TextBlock Name="CurrentPathDisplay" Classes="BodyStrongTextBlockStyle" MaxHeight="50" />
<TextBlock Name="CurrentPathDescription" Classes="BodyTextBlockStyle" Foreground="{DynamicResource TextFillColorSecondary}" MaxHeight="50" />
</StackPanel>
</Grid>
<Grid MinHeight="38"
IsVisible="{Binding DataModelPath, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNull}}" ColumnDefinitions="*,Auto"
IsVisible="{CompiledBinding DataModelPath, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNull}}" ColumnDefinitions="*,Auto"
RowDefinitions="*,*">
<TextBlock Grid.Column="0" Grid.Row="0" Classes="BodyStrongTextBlockStyle">Welcome to the data model picker</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" Foreground="{DynamicResource TextFillColorSecondary}">Select a value from the data model below</TextBlock>
@@ -53,19 +53,19 @@
<TreeView Grid.Row="2"
Name="DataModelTreeView"
ItemsSource="{Binding DataModelViewModel.Children, RelativeSource={RelativeSource TemplatedParent}}">
ItemsSource="{CompiledBinding DataModelViewModel.Children, RelativeSource={RelativeSource TemplatedParent}}">
<TreeView.Styles>
<Style Selector="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes, Mode=OneWay}" />
<Setter Property="IsExpanded" Value="{CompiledBinding IsVisualizationExpanded, Mode=TwoWay, DataType=dataModel:DataModelVisualizationViewModel}" />
<Setter Property="IsEnabled" Value="{CompiledBinding IsMatchingFilteredTypes, Mode=OneWay, DataType=dataModel:DataModelVisualizationViewModel}" />
</Style>
</TreeView.Styles>
<TreeView.DataTemplates>
<TreeDataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}" ItemsSource="{Binding Children}">
<TreeDataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}" ItemsSource="{CompiledBinding Children}">
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0" Text="{Binding PropertyDescription.Name}" ToolTip.Tip="{Binding PropertyDescription.Description}" />
<TextBlock Grid.Column="0" Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
<TextBlock Grid.Column="1"
Text="{Binding DisplayValue}"
Text="{CompiledBinding DisplayValue}"
FontFamily="Consolas"
HorizontalAlignment="Right"
Margin="0 0 10 0" />
@@ -75,29 +75,29 @@
<TreeDataTemplate DataType="{x:Type dataModel:DataModelPropertyViewModel}">
<Grid ColumnDefinitions="Auto,*">
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock Text="{Binding PropertyDescription.Name}" ToolTip.Tip="{Binding PropertyDescription.Description}" />
<TextBlock Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
<TextBlock Text=" changed"
ToolTip.Tip="{Binding PropertyDescription.Description}"
IsVisible="{Binding IsEventPicker, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dataModelPicker:DataModelPicker}}}"/>
ToolTip.Tip="{CompiledBinding PropertyDescription.Description}"
IsVisible="{CompiledBinding IsEventPicker, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dataModelPicker:DataModelPicker}}}"/>
</StackPanel>
<ContentControl Grid.Column="1" Content="{Binding DisplayViewModel}" FontFamily="Consolas" Margin="0 0 10 0" />
<ContentControl Grid.Column="1" Content="{CompiledBinding DisplayViewModel}" FontFamily="Consolas" Margin="0 0 10 0" />
</Grid>
</TreeDataTemplate>
<TreeDataTemplate DataType="{x:Type dataModel:DataModelListViewModel}">
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0" Text="{Binding PropertyDescription.Name}" ToolTip.Tip="{Binding PropertyDescription.Description}" />
<TextBlock Grid.Column="0" Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
<TextBlock Grid.Column="1"
Text="{Binding CountDisplay, Mode=OneWay}"
Text="{CompiledBinding CountDisplay, Mode=OneWay}"
FontFamily="Consolas"
HorizontalAlignment="Right"
Margin="0 0 10 0" />
</Grid>
</TreeDataTemplate>
<TreeDataTemplate DataType="{x:Type dataModel:DataModelEventViewModel}" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding PropertyDescription.Name}" ToolTip.Tip="{Binding PropertyDescription.Description}" />
<TreeDataTemplate DataType="{x:Type dataModel:DataModelEventViewModel}" ItemsSource="{CompiledBinding Children}">
<TextBlock Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
</TreeDataTemplate>
</TreeView.DataTemplates>
</TreeView>
@@ -103,10 +103,10 @@
</ItemsControl.Styles>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="core:ColorGradientStop">
<gradientPicker:GradientPickerColorStop ColorStop="{Binding}"
PositionReference="{Binding $parent[Border]}"
<gradientPicker:GradientPickerColorStop ColorStop="{CompiledBinding}"
PositionReference="{CompiledBinding $parent[Border]}"
Classes="gradient-handle"
GradientPicker="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type gradientPicker:GradientPicker}}}">
GradientPicker="{CompiledBinding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type gradientPicker:GradientPicker}}}">
</gradientPicker:GradientPickerColorStop>
</DataTemplate>
</ItemsControl.ItemTemplate>
@@ -152,7 +152,7 @@
<ItemsControl.ItemTemplate>
<DataTemplate DataType="core:ColorGradientStop">
<Border Classes="stop-position">
<TextBlock Text="{Binding Position}"></TextBlock>
<TextBlock Text="{CompiledBinding Position}"></TextBlock>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
@@ -174,8 +174,8 @@
UseColorTriangle="True"
IsMoreButtonVisible="True"
IsVisible="{TemplateBinding SelectedColorStop, Converter={x:Static ObjectConverters.IsNotNull}}"
IsCompact="{Binding IsCompact, RelativeSource={RelativeSource TemplatedParent}}"
Color="{Binding SelectedColorStop.Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource SKColorToColorConverter}}" />
IsCompact="{CompiledBinding IsCompact, RelativeSource={RelativeSource TemplatedParent}}"
Color="{CompiledBinding SelectedColorStop.Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource SKColorToColorConverter}}" />
</Border>
<Grid Grid.Row="2" Grid.Column="1" RowDefinitions="*,Auto">
@@ -196,19 +196,19 @@
BorderBrush="{DynamicResource ButtonBorderBrush}"
ClipToBounds="True"
Background="{DynamicResource LightCheckerboardBrush}">
<Border CornerRadius="4" Margin="-2" Background="{Binding Color, Converter={StaticResource SKColorToBrushConverter}}" />
<Border CornerRadius="4" Margin="-2" Background="{CompiledBinding Color, Converter={StaticResource SKColorToBrushConverter}}" />
</Border>
<TextBox Grid.Column="1" Text="{Binding Color, Converter={StaticResource SKColorToStringConverter}}" />
<TextBox Grid.Column="1" Text="{CompiledBinding Color, Converter={StaticResource SKColorToStringConverter}}" />
<NumericUpDown Grid.Column="2" FormatString="F3" ShowButtonSpinner="False" Margin="5 0" Minimum="0" Maximum="1" Increment="0.01">
<Interaction.Behaviors>
<behaviors:LostFocusNumericUpDownBindingBehavior Value="{Binding Position}" />
<behaviors:LostFocusNumericUpDownBindingBehavior Value="{CompiledBinding Position}" />
</Interaction.Behaviors>
</NumericUpDown>
<Button Name="DeleteButton"
Grid.Column="3"
Classes="icon-button"
Command="{Binding DeleteStop, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type gradientPicker:GradientPicker}}}"
CommandParameter="{Binding}">
Command="{CompiledBinding DeleteStop, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type gradientPicker:GradientPicker}}}"
CommandParameter="{CompiledBinding}">
<avalonia:MaterialIcon Kind="Close" />
</Button>
</Grid>