diff --git a/samples/ControlCatalog/Pages/ViewboxPage.xaml b/samples/ControlCatalog/Pages/ViewboxPage.xaml index 6e649b39a5..ef802db33e 100644 --- a/samples/ControlCatalog/Pages/ViewboxPage.xaml +++ b/samples/ControlCatalog/Pages/ViewboxPage.xaml @@ -12,8 +12,9 @@ - + @@ -25,7 +26,7 @@ - + diff --git a/samples/ControlCatalog/Pages/ViewboxPage.xaml.cs b/samples/ControlCatalog/Pages/ViewboxPage.xaml.cs index 7a2bceb8f2..94b3f3ea14 100644 --- a/samples/ControlCatalog/Pages/ViewboxPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ViewboxPage.xaml.cs @@ -6,23 +6,18 @@ namespace ControlCatalog.Pages { public class ViewboxPage : UserControl { - private readonly Viewbox _viewbox; - private readonly ComboBox _stretchSelector; - public ViewboxPage() { InitializeComponent(); - _viewbox = this.FindControl("Viewbox"); - - _stretchSelector = this.FindControl("StretchSelector"); + var stretchSelector = this.FindControl("StretchSelector"); - _stretchSelector.Items = new[] + stretchSelector.Items = new[] { Stretch.Uniform, Stretch.UniformToFill, Stretch.Fill, Stretch.None }; - _stretchSelector.SelectedIndex = 0; + stretchSelector.SelectedIndex = 0; var stretchDirectionSelector = this.FindControl("StretchDirectionSelector"); @@ -38,10 +33,5 @@ namespace ControlCatalog.Pages { AvaloniaXamlLoader.Load(this); } - - private void StretchSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) - { - _viewbox.Stretch = (Stretch) _stretchSelector.SelectedItem!; - } } } diff --git a/src/Avalonia.Controls/Viewbox.cs b/src/Avalonia.Controls/Viewbox.cs index b65f4b31d8..15ca070de2 100644 --- a/src/Avalonia.Controls/Viewbox.cs +++ b/src/Avalonia.Controls/Viewbox.cs @@ -12,7 +12,8 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly AvaloniaProperty StretchProperty = - AvaloniaProperty.Register(nameof(Stretch), Stretch.Uniform); + AvaloniaProperty.RegisterDirect(nameof(Stretch), + v => v.Stretch, (c, v) => c.Stretch = v, Stretch.Uniform); /// /// Defines the property.