Skip to content

Commit

Permalink
fix: Ensure AffectsMeasure and AffectsArrange are aligned with WinUI3
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 30, 2024
1 parent 8122799 commit 0774906
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/Uno.UI/Mixins/DependencyPropertyMixins.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

.Class("Control")
.Property("BackgroundSizing", "BackgroundSizing", "default")
.Property("HorizontalContentAlignment", "HorizontalAlignment", "(Uno.UI.FeatureConfiguration.Control.UseLegacyContentAlignment ? HorizontalAlignment.Left : HorizontalAlignment.Center)")
.Property("VerticalContentAlignment", "VerticalAlignment", "(Uno.UI.FeatureConfiguration.Control.UseLegacyContentAlignment ? VerticalAlignment.Top : VerticalAlignment.Center)")
.Property("HorizontalContentAlignment", "HorizontalAlignment", "(Uno.UI.FeatureConfiguration.Control.UseLegacyContentAlignment ? HorizontalAlignment.Left : HorizontalAlignment.Center)", frameworkPropertyOption: "AffectsArrange")
.Property("VerticalContentAlignment", "VerticalAlignment", "(Uno.UI.FeatureConfiguration.Control.UseLegacyContentAlignment ? VerticalAlignment.Top : VerticalAlignment.Center)", frameworkPropertyOption: "AffectsArrange")
.Class("Picker", condition: "__IOS__")
.Property("ItemsSource", "object", "null")
.Property("SelectedItem", "object", "null")
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/ContentControl/ContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public object Content
// (ie if created in code by new SomeControl())
// NOTE: There's a case we currently don't support: if the Content is a DependencyObject but *not* a FrameworkElement, then
// the DataContext won't get propagated and any bindings won't get updated.
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext,
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.AffectsMeasure,
propertyChangedCallback: (s, e) => ((ContentControl)s)?.OnContentChanged(e.OldValue, e.NewValue)
)
);
Expand All @@ -125,7 +125,7 @@ public DataTemplate ContentTemplate
typeof(ContentControl),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext,
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((ContentControl)s)?.OnContentTemplateChanged(e.OldValue as DataTemplate, e.NewValue as DataTemplate)
)
);
Expand Down
22 changes: 14 additions & 8 deletions src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,15 @@ public ControlTemplate Template
set { SetValue(TemplateProperty, value); }
}

// Using a DependencyProperty as the backing store for Template. This enables animation, styling, binding, etc...
public static DependencyProperty TemplateProperty { get; } =
DependencyProperty.Register("Template", typeof(ControlTemplate), typeof(Control), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext, (s, e) => ((Control)s)?.OnTemplateChanged(e)));
DependencyProperty.Register(
nameof(Template),
typeof(ControlTemplate),
typeof(Control),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnTemplateChanged(e)));

private void OnTemplateChanged(DependencyPropertyChangedEventArgs e)
{
Expand Down Expand Up @@ -640,7 +646,7 @@ public FontWeight FontWeight
typeof(Control),
new FrameworkPropertyMetadata(
FontWeights.Normal,
FrameworkPropertyMetadataOptions.Inherits,
FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnFontWeightChanged((FontWeight)e.OldValue, (FontWeight)e.NewValue)
)
);
Expand All @@ -662,7 +668,7 @@ public double FontSize
typeof(Control),
new FrameworkPropertyMetadata(
14.0,
FrameworkPropertyMetadataOptions.Inherits,
FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnFontSizeChanged((double)e.OldValue, (double)e.NewValue)
)
);
Expand All @@ -684,7 +690,7 @@ public FontFamily FontFamily
typeof(Control),
new FrameworkPropertyMetadata(
FontFamily.Default,
FrameworkPropertyMetadataOptions.Inherits,
FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnFontFamilyChanged(e.OldValue as FontFamily, e.NewValue as FontFamily)
)
);
Expand All @@ -705,7 +711,7 @@ public FontStyle FontStyle
typeof(Control),
new FrameworkPropertyMetadata(
FontStyle.Normal,
FrameworkPropertyMetadataOptions.Inherits,
FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnFontStyleChanged((FontStyle)e.OldValue, (FontStyle)e.NewValue)
)
);
Expand Down Expand Up @@ -739,7 +745,7 @@ public Thickness Padding
typeof(Control),
new FrameworkPropertyMetadata(
Thickness.Empty,
FrameworkPropertyMetadataOptions.None,
FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnPaddingChanged((Thickness)e.OldValue, (Thickness)e.NewValue)
)
);
Expand All @@ -762,7 +768,7 @@ public Thickness BorderThickness
typeof(Control),
new FrameworkPropertyMetadata(
Thickness.Empty,
FrameworkPropertyMetadataOptions.None,
FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Control)s)?.OnBorderThicknessChanged((Thickness)e.OldValue, (Thickness)e.NewValue)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public DataTemplate HeaderTemplate
name: "HeaderTemplate",
propertyType: typeof(DataTemplate),
ownerType: typeof(DatePicker),
typeMetadata: new FrameworkPropertyMetadata(default(DataTemplate), FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext));
typeMetadata: new FrameworkPropertyMetadata(default(DataTemplate), FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.AffectsMeasure));

public object Header
{
Expand All @@ -190,7 +190,7 @@ public object Header
name: "Header",
propertyType: typeof(object),
ownerType: typeof(DatePicker),
typeMetadata: new FrameworkPropertyMetadata(default(object)));
typeMetadata: new FrameworkPropertyMetadata(default(object), FrameworkPropertyMetadataOptions.AffectsMeasure));

public string DayFormat
{
Expand Down
6 changes: 3 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/Grid/ColumnDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)

private static GridLength GetWidthDefaultValue() => GridLengthHelper.OneStar;

[GeneratedDependencyProperty]
[GeneratedDependencyProperty(Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty WidthProperty { get; } = CreateWidthProperty();

public GridLength Width
Expand All @@ -45,7 +45,7 @@ public static implicit operator ColumnDefinition(string value)
return new ColumnDefinition { Width = GridLength.ParseGridLength(value).First() };
}

[GeneratedDependencyProperty(DefaultValue = 0d)]
[GeneratedDependencyProperty(DefaultValue = 0d, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty MinWidthProperty { get; } = CreateMinWidthProperty();

public double MinWidth
Expand All @@ -54,7 +54,7 @@ public double MinWidth
set => SetMinWidthValue(value);
}

[GeneratedDependencyProperty(DefaultValue = double.PositiveInfinity)]
[GeneratedDependencyProperty(DefaultValue = double.PositiveInfinity, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty MaxWidthProperty { get; } = CreateMaxWidthProperty();

public double MaxWidth
Expand Down
14 changes: 7 additions & 7 deletions src/Uno.UI/UI/Xaml/Controls/Grid/Grid.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Thickness BorderThickness

private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty;

[GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderThicknessPropertyChanged), Options = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange)]
[GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderThicknessPropertyChanged), Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty();

private void OnBorderThicknessPropertyChanged(Thickness oldValue, Thickness newValue)
Expand Down Expand Up @@ -131,7 +131,7 @@ private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius n
#endregion

#region Row Property
[GeneratedDependencyProperty(DefaultValue = 0, Options = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
[GeneratedDependencyProperty(DefaultValue = 0, Options = FrameworkPropertyMetadataOptions.AffectsMeasure, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
public static DependencyProperty RowProperty { get; } = CreateRowProperty();

public static int GetRow(View view) => GetRowValue(view);
Expand All @@ -148,7 +148,7 @@ private static void OnRowChanged(DependencyObject instance, DependencyPropertyCh
#endregion

#region Column Property
[GeneratedDependencyProperty(DefaultValue = 0, Options = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
[GeneratedDependencyProperty(DefaultValue = 0, Options = FrameworkPropertyMetadataOptions.AffectsMeasure, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
public static DependencyProperty ColumnProperty { get; } = CreateColumnProperty();

public static int GetColumn(View view) => GetColumnValue(view);
Expand All @@ -166,7 +166,7 @@ private static void OnColumnChanged(DependencyObject instance, DependencyPropert
#endregion

#region RowSpan Property
[GeneratedDependencyProperty(DefaultValue = 1, Options = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
[GeneratedDependencyProperty(DefaultValue = 1, Options = FrameworkPropertyMetadataOptions.AffectsMeasure, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
public static DependencyProperty RowSpanProperty { get; } = CreateRowSpanProperty();

public static int GetRowSpan(View view) => GetRowSpanValue(view as UIElement);
Expand All @@ -191,7 +191,7 @@ private static void OnRowSpanChanged(DependencyObject instance, DependencyProper
#endregion

#region ColumnSpan Property
[GeneratedDependencyProperty(DefaultValue = 1, Options = FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
[GeneratedDependencyProperty(DefaultValue = 1, Options = FrameworkPropertyMetadataOptions.AffectsMeasure, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallback = true)]
public static DependencyProperty ColumnSpanProperty { get; } = CreateColumnSpanProperty();

public static int GetColumnSpan(View view) => GetColumnSpanValue(view as UIElement);
Expand Down Expand Up @@ -227,7 +227,7 @@ public double RowSpacing
typeof(Grid),
new FrameworkPropertyMetadata(
default(double),
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange));
FrameworkPropertyMetadataOptions.AffectsMeasure));

public double ColumnSpacing
{
Expand All @@ -241,6 +241,6 @@ public double ColumnSpacing
typeof(Grid),
new FrameworkPropertyMetadata(
default(double),
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange));
FrameworkPropertyMetadataOptions.AffectsMeasure));
}
}
6 changes: 3 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/Grid/RowDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)

private static GridLength GetHeightDefaultValue() => GridLengthHelper.OneStar;

[GeneratedDependencyProperty]
[GeneratedDependencyProperty(Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty HeightProperty { get; } = CreateHeightProperty();

public GridLength Height
Expand All @@ -44,7 +44,7 @@ public static implicit operator RowDefinition(string value)
return new RowDefinition { Height = GridLength.ParseGridLength(value).First() };
}

[GeneratedDependencyProperty(DefaultValue = 0d)]
[GeneratedDependencyProperty(DefaultValue = 0d, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty MinHeightProperty { get; } = CreateMinHeightProperty();

public double MinHeight
Expand All @@ -53,7 +53,7 @@ public double MinHeight
set => SetMinHeightValue(value);
}

[GeneratedDependencyProperty(DefaultValue = double.PositiveInfinity)]
[GeneratedDependencyProperty(DefaultValue = double.PositiveInfinity, Options = FrameworkPropertyMetadataOptions.AffectsMeasure)]
public static DependencyProperty MaxHeightProperty { get; } = CreateMaxHeightProperty();
public double MaxHeight
{
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Image/Image.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public ImageSource Source
typeof(Image),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Image)s).OnSourceChanged((ImageSource)e.NewValue)));

/// <summary>
Expand All @@ -46,6 +47,7 @@ public Stretch Stretch
typeof(Image),
new FrameworkPropertyMetadata(
Stretch.Uniform,
FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((Image)s).OnStretchChanged((Stretch)e.NewValue, (Stretch)e.OldValue)));

#if !__WASM__
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ItemsPanelTemplate ItemsPanel
typeof(ItemsControl),
new FrameworkPropertyMetadata(
(ItemsPanelTemplate)null,
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext,
FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((ItemsControl)s)?.OnItemsPanelChanged((ItemsPanelTemplate)e.OldValue, (ItemsPanelTemplate)e.NewValue)
)
);
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public Thickness Padding
typeof(ItemsPresenter),
new FrameworkPropertyMetadata(
(Thickness)Thickness.Empty,
FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((ItemsPresenter)s)?.OnPaddingChanged((Thickness)e.OldValue, (Thickness)e.NewValue)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ImageSource PosterSource
nameof(PosterSource),
typeof(ImageSource),
typeof(MediaPlayerElement),
new FrameworkPropertyMetadata(default(ImageSource), OnPosterSourceChanged));
new FrameworkPropertyMetadata(default(ImageSource), FrameworkPropertyMetadataOptions.AffectsMeasure, OnPosterSourceChanged));

private static void OnPosterSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public bool IsFullWindow
nameof(IsFullWindow),
typeof(bool),
typeof(MediaPlayerElement),
new FrameworkPropertyMetadata(false, OnIsFullWindowChanged));
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsMeasure, OnIsFullWindowChanged));


private static void OnIsFullWindowChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
Expand Down Expand Up @@ -284,7 +284,7 @@ public bool AreTransportControlsEnabled
nameof(AreTransportControlsEnabled),
typeof(bool),
typeof(MediaPlayerElement),
new FrameworkPropertyMetadata(false));
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsMeasure));

#endregion

Expand All @@ -301,7 +301,7 @@ public Stretch Stretch
nameof(Stretch),
typeof(Stretch),
typeof(MediaPlayerElement),
new FrameworkPropertyMetadata(Stretch.Uniform));
new FrameworkPropertyMetadata(Stretch.Uniform, FrameworkPropertyMetadataOptions.AffectsMeasure));

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public Stretch Stretch
nameof(Stretch),
typeof(Stretch),
typeof(MediaPlayerPresenter),
new FrameworkPropertyMetadata(Stretch.Uniform, (s, e) => ((MediaPlayerPresenter)s).OnStretchChanged((Stretch)e.NewValue, (Stretch)e.OldValue)));
new FrameworkPropertyMetadata(
Stretch.Uniform,
FrameworkPropertyMetadataOptions.AffectsMeasure,
(s, e) => ((MediaPlayerPresenter)s).OnStretchChanged((Stretch)e.NewValue, (Stretch)e.OldValue)));

#endregion

Expand All @@ -127,7 +130,7 @@ public bool IsFullWindow
nameof(IsFullWindow),
typeof(bool),
typeof(MediaPlayerPresenter),
new FrameworkPropertyMetadata(false));
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsMeasure));

#endregion

Expand Down
Loading

0 comments on commit 0774906

Please sign in to comment.