Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBox TextWrapping.Wrap inside Grid with IsSharedSizeScope #10520

Open
n9 opened this issue Feb 27, 2025 · 4 comments
Open

TextBox TextWrapping.Wrap inside Grid with IsSharedSizeScope #10520

n9 opened this issue Feb 27, 2025 · 4 comments

Comments

@n9
Copy link

n9 commented Feb 27, 2025

Description

TextBox TextWrapping=Wrap does not work when contained in Grid within SharedSizeScope.

Reproduction Steps

var sharedSizeGroup = "foo";

Grid CreateGrid()
{
	var g = new Grid();
	g.ColumnDefinitions.Add(new()
	{
		SharedSizeGroup = sharedSizeGroup
	});
	g.Children.Add(new TextBox
	{
		Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
		TextWrapping = TextWrapping.Wrap
	});
	return g;
}

var stack = new StackPanel
{
	Orientation = Orientation.Vertical
};

Grid.SetIsSharedSizeScope(stack, true); // <-- the text will wrap when this line is removed

stack.Children.Add(CreateGrid());
stack.Children.Add(CreateGrid());

new Window
{
	Width = 400,
	Height = 300,
	Content = stack,
}.Show();

Expected behavior

TextWrapping.Wrap will work.

Image

Actual behavior

TextWrapping.Wrap is not working.

Image

Regression?

Seems not.

Known Workarounds

I am not aware of any.

Impact

Cannot use both IsSharedSizeScope and TextWrapping.Wrap. Cannot create multiple field lists where text is wrapped.

Configuration

.NET 9.0.1

Other information

No response

@miloush
Copy link
Contributor

miloush commented Feb 27, 2025

That seems by design.

IsSharedScope says:

Columns and rows participating in size sharing do not respect Star sizing. In this scenario, Star sizing is treated as Auto.

Where Star is sized to available space, while Auto is sized to content, as documented here

@n9
Copy link
Author

n9 commented Feb 27, 2025

@miloush Ok, thank you for the explanation. Do you know why this limitation exists? Is it a limitation of how WPF layout (measure/arrange) works, so it is "impossible" to share size between grids? Or is it just a limitation of the current implementation of Grid, but it can be "easily" improved to support Star sizing within size sharing?

@miloush
Copy link
Contributor

miloush commented Feb 27, 2025

I think it gets a bit more complicated, star represents potentially different value in each grid. The grids don't have to have the same width for example. If you had two grids with two columns, one of them shared size, but the grids were of different size. What would you expect the shared size to be? Half of the smaller grid, half of the larger grid, or actually different width in each grid? Sizing to content gives you an absolute number that can be shared across several grids.

@n9
Copy link
Author

n9 commented Feb 27, 2025

@miloush Ok, column/row size sharing is not a suitable concept for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants