Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a WPF ListBox, with a custom ItemsPanel template, resize itself based on the size of its items
    primarykey
    data
    text
    <p>This is a follow up question to <a href="https://stackoverflow.com/questions/1545519/change-how-items-are-displayed-wpf-list-box">this</a>, which was answered. </p> <p>Using the code:</p> <pre><code>&lt;ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled"&gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Vertical"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;/ListBox&gt; </code></pre> <p>You can create a list where the items populate the <code>ListBox</code> in columns from left to right and the last item in a particular column is never cutoff (meaning if the item was to tall to fit, it is moved to the top of the next column). How could I now dynamically adjust the <code>Width</code> of the <code>ListBox</code> to 'fit' it's items and get that same behavior horizontally. So suppose the following:</p> <p>If, at a given <code>Height</code>, there only needed to be one <code>Column</code> to fit all of the items the <code>Width</code> of the <code>ListBox</code> should be the size of the <code>Width</code> of the items. </p> <p>Or, at a given <code>Height</code> there needs to be four <code>Column</code>s, it would need to be size to four times the <code>Width</code> of the items.</p> <p>Finally, say at a given <code>Height</code> there needs to be more <code>Column</code>s than the maximum allowed <code>Width</code> of the<code>ListBox</code>, it would need to calculate how wide it should be so that the items in the <code>Column</code>s that would not be able to fit were not truncated but just not shown until the user scrolled to the right.</p> <p>Thanks for your help!! </p> <p><strong>EDIT:</strong></p> <p>I think a simpler way to phrase the above is that I'm looking for a way to avoid 'clipping' items in the list. I'd like to create a list that displays items in grid but where you wouldn't have to scroll because some items were partially covered and would require you to scroll to the right or left to see the remainder of that item (though the list could only be so wide or tall and if there were enough items you'd still need to scroll to see all of them, just any items you saw should be fully displayed). Also I only care about the initial drawing of the list. It doesn't have to 'snap' items to always fit but it should be able to be scrolled so that it fills the available space completely with the items it does display.</p> <p>It seemed to me the key do doing this is to figure out the size of a list item at runtime and the size of the content container in the listbox and then you could adjust it to completely fit so many items at once before the list is initially drawn? </p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload