A novice at WPF / XAML, I've been wrestling with layout and trying to get it uniform. I'm using a listbox of grids, with different data in different columns. I'll start by saying the desired behavior: uniform start and end positions for the columns, which I thought could be achieved by using *
-based Width
s in the ColumnDefinition
s.
And in the most recent diff from the GitHub link at the bottom, with the dummy data, the columns are uniform with various string lengths. But for some reason when I use the actual data drawn from the DirectorySizer
s the uniformity goes out the window, where the second column starts at different positions based on the length of DirPath
. The only thing I could think was if the data was somehow longer than the column, which doesn't seem to be the case (inspecting in memory DirPath
comes out appropriately trimmed).
Any solutions / explanations for this? I'm at a loss.
You should look into using Grid.IsSharedSizeScope on your listbox. Using this you can make all the grids share the same column size based on the property "SharedSizeGroup" in the columnDefinition. I know this isn't a thorough explanation so please just google on Grid.IsSharedSizeScope and you find what you need.
Also the diference in behaviour you see may be explained by the different structure of the data source you are using. Instead of doing an array of string where the exact same value gets bound to each column try setting up a class with two different string values and binding to that. That way it will be a more valid comparision to your DirectorySizer object
Apparently something about INotifyPropertyChanged
causes the layout to go out of whack. When the Notify()
occurs and the new content is displayed, the layout system simply keeps the padding between the content and the grid line, causing the alignment to deform if the content's a different size.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.