diff --git a/src/Avalonia.Controls.DataGrid/DataGridRow.cs b/src/Avalonia.Controls.DataGrid/DataGridRow.cs index 8bc76543ba..04a1575486 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRow.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRow.cs @@ -881,10 +881,10 @@ namespace Avalonia.Controls && (double.IsNaN(_detailsContent.Height)) && (AreDetailsVisible) && (!double.IsNaN(_detailsDesiredHeight)) - && !DoubleUtil.AreClose(_detailsContent.Bounds.Height, _detailsDesiredHeight) + && !DoubleUtil.AreClose(_detailsContent.Bounds.Inflate(_detailsContent.Margin).Height, _detailsDesiredHeight) && Slot != -1) { - _detailsDesiredHeight = _detailsContent.Bounds.Height; + _detailsDesiredHeight = _detailsContent.Bounds.Inflate(_detailsContent.Margin).Height; if (true) { @@ -943,6 +943,16 @@ namespace Avalonia.Controls _previousDetailsHeight = newValue.Height; } } + private void DetailsContent_BoundsChanged(Rect newValue) + { + if(_detailsContent != null) + DetailsContent_SizeChanged(newValue.Inflate(_detailsContent.Margin)); + } + private void DetailsContent_MarginChanged(Thickness newValue) + { + if (_detailsContent != null) + DetailsContent_SizeChanged(_detailsContent.Bounds.Inflate(newValue)); + } //TODO Animation // Sets AreDetailsVisible on the row and animates if necessary @@ -997,7 +1007,7 @@ namespace Avalonia.Controls } } } - + internal void ApplyDetailsTemplate(bool initializeDetailsPreferredHeight) { if (_detailsElement != null && AreDetailsVisible) @@ -1023,8 +1033,11 @@ namespace Avalonia.Controls if (_detailsContent != null) { _detailsContentSizeSubscription = - _detailsContent.GetObservable(BoundsProperty) - .Subscribe(DetailsContent_SizeChanged); + System.Reactive.Disposables.StableCompositeDisposable.Create( + _detailsContent.GetObservable(BoundsProperty) + .Subscribe(DetailsContent_BoundsChanged), + _detailsContent.GetObservable(MarginProperty) + .Subscribe(DetailsContent_MarginChanged)); _detailsElement.Children.Add(_detailsContent); } } @@ -1053,4 +1066,4 @@ namespace Avalonia.Controls //TODO Styles -} \ No newline at end of file +} diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github b/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github index a73c523483..610cda30c6 160000 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github @@ -1 +1 @@ -Subproject commit a73c5234831267b23160e01a9fbc83be633f69fc +Subproject commit 610cda30c69e32e83c8235060606480904c937bc diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs index 3511919e39..5e346e5289 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs @@ -158,6 +158,55 @@ namespace Avalonia.Markup.Xaml.UnitTests Assert.Equal("321", loaded.Test); } + + void AssertThrows(Action callback, Func check) + { + try + { + callback(); + } + catch (Exception e) when (check(e)) + { + return; + } + + throw new Exception("Expected exception was not thrown"); + } + + public static object SomeStaticProperty { get; set; } + + [Fact] + public void Bug2570() + { + SomeStaticProperty = "123"; + AssertThrows(() => new AvaloniaXamlLoader() {IsDesignMode = true} + .Load(@" +", typeof(XamlIlTests).Assembly), + e => e.Message.Contains("Unable to resolve ") + && e.Message.Contains(" as static field, property, constant or enum value")); + + } + + [Fact] + public void Design_Mode_DataContext_Should_Be_Set() + { + SomeStaticProperty = "123"; + + var loaded = (UserControl)new AvaloniaXamlLoader() {IsDesignMode = true} + .Load(@" +", typeof(XamlIlTests).Assembly); + Assert.Equal(Design.GetDataContext(loaded), SomeStaticProperty); + } } public class XamlIlBugTestsEventHandlerCodeBehind : Window @@ -188,7 +237,7 @@ namespace Avalonia.Markup.Xaml.UnitTests ((ItemsControl)Content).Items = new[] {"123"}; } } - + public class XamlIlClassWithCustomProperty : UserControl { public string Test { get; set; }