sohum
sohum

Reputation: 3227

Layout control for elements with a distributed width

I'm not exactly sure how to phrase this question, so I'll just explain what I'm trying to do. I have a Model/ViewModel that essentially contains a list of elements. Some elements on the list should be represented with a static-width shape (such as a 10x10 pixel rectangle) whereas others should stretch to equally distribute the remaining width between all elements.

For example, let's assume the list contains the following:

(static static dynamic dynamic dynamic static dynamic dynamic)

The static elements have a width of 10px. I want each of the dynamic elements to equally take up the remaining room in the container. For example, if my container has 100 pixels, since I have 3 static elements, I want the rest of the 70 pixels to be distributed across the 5 dynamic elements (14 pixels each).

Is there a WPF control that does this or will I need to dynamically re-size and add the controls on window resize?

Upvotes: 2

Views: 250

Answers (2)

Grokys
Grokys

Reputation: 16526

It sounds like you could use a standard Grid control. Add a column for each element, and set the column width to a specific size for those elements that require it, and use * for the remaining elements.

Upvotes: 2

brunnerh
brunnerh

Reputation: 184416

In a Grid (- read this -) you can have rows and columns do that, change the RowDefiniton.Height/ColumnDefiniton.Width to Auto to size to content and to * to distribute remainding space.

Upvotes: 2

Related Questions