Grid.ColumnDefinition - forcing a column to fit the width of the longest string in two grids.. #15070
Replies: 6 comments
-
Set ColumnDefinition=Auto |
Beta Was this translation helpful? Give feedback.
-
Sorry, I miss-stated the question. I have two grids and I'm trying to have column N be the same width in both grids without hardcoding a Width value. I'm currently experimenting with a custom label that can enforce the width but I'm wondering if there's a better way to do it via Grid. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Can you share the code ? |
Beta Was this translation helpful? Give feedback.
-
See my ColorSelector sample. My original implementation had 4 ARGB sliders for editing the Color fields independently in the main page. That solved the problem of having the associated Name labels to be the same size, it did not solve the problem of the dynamic Value labels. Using StringFormat:'{0:000}' solved the value part but I felt the leading zeros were distracting. Worse, making changes across the grid was getting cumbersome (4 rows of 5 columns). I decided to refactore each 'slider group' into a ContentView containing a single grid with 5 columns. I want to have the Name and Value fields match across instances. The only solution I could come up with is to derive a Label class that supports a custom DesiredWidth to allow me to define the same text width for these two columns. |
Beta Was this translation helpful? Give feedback.
-
I've prototyped one solution, Bindable Grid but this only solves the problem if the column contains static content. If the column contains dynamic content, I still don't have a method for forcing the column to a fixed width; other than using Absolute. What I really need is a method for defining an absolute width that is based on the maximum width of any 'possible' content. For example, if a column contains dynamic numeric values, the width of the column changes based on the data. What I would like is to set the width based on the maximum length of the range of values; such as 0...255. |
Beta Was this translation helpful? Give feedback.
-
Have you tried StringFormat:'{0,3}'? That should format it as a string of length 3 with leading spaces. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a multi-row Grid and I want one column to be the width of the longest string in any of the rows. Is there a declaration I can use to make this happen?
Beta Was this translation helpful? Give feedback.
All reactions