diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs
index b561a3423f..387af58255 100644
--- a/src/Avalonia.Controls/TextBox.cs
+++ b/src/Avalonia.Controls/TextBox.cs
@@ -316,8 +316,7 @@ namespace Avalonia.Controls
!AcceptsReturn &&
Text?.Length > 0)
{
- SelectionStart = 0;
- SelectionEnd = Text.Length;
+ SelectAll();
}
else
{
@@ -673,8 +672,7 @@ namespace Avalonia.Controls
SelectionEnd = StringUtils.NextWord(text, index);
break;
case 3:
- SelectionStart = 0;
- SelectionEnd = text.Length;
+ SelectAll();
break;
}
}
@@ -896,7 +894,10 @@ namespace Avalonia.Controls
CaretIndex = caretIndex;
}
- private void SelectAll()
+ ///
+ /// Select all text in the TextBox
+ ///
+ public void SelectAll()
{
SelectionStart = 0;
SelectionEnd = Text?.Length ?? 0;
diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs
index 0c37858223..6554237b3a 100644
--- a/src/Avalonia.Controls/Window.cs
+++ b/src/Avalonia.Controls/Window.cs
@@ -529,7 +529,7 @@ namespace Avalonia.Controls
{
var sizeToContent = SizeToContent;
var clientSize = ClientSize;
- Size constraint = clientSize;
+ var constraint = availableSize;
if ((sizeToContent & SizeToContent.Width) != 0)
{
diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs
index 0508edd92f..81699b075c 100644
--- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs
@@ -341,11 +341,62 @@ namespace Avalonia.Controls.UnitTests
}
}
+ [Fact]
+ public void Child_Should_Be_Measured_With_Width_And_Height_If_SizeToContent_Is_Manual()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var child = new ChildControl();
+ var target = new Window
+ {
+ Width = 100,
+ Height = 50,
+ SizeToContent = SizeToContent.Manual,
+ Content = child
+ };
+
+ target.Show();
+
+ Assert.Equal(new Size(100, 50), child.MeasureSize);
+ }
+ }
+
+ [Fact]
+ public void Child_Should_Be_Measured_With_Infinity_If_SizeToContent_Is_WidthAndHeight()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var child = new ChildControl();
+ var target = new Window
+ {
+ Width = 100,
+ Height = 50,
+ SizeToContent = SizeToContent.WidthAndHeight,
+ Content = child
+ };
+
+ target.Show();
+
+ Assert.Equal(Size.Infinity, child.MeasureSize);
+ }
+ }
+
private IWindowImpl CreateImpl(Mock renderer)
{
return Mock.Of(x =>
x.Scaling == 1 &&
x.CreateRenderer(It.IsAny()) == renderer.Object);
}
+
+ private class ChildControl : Control
+ {
+ public Size MeasureSize { get; private set; }
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ MeasureSize = availableSize;
+ return base.MeasureOverride(availableSize);
+ }
+ }
}
}