Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resize a stacklayoutpanel to fit its contents?
    text
    copied!<p>I have searched telerik's site for a while now and can not find any mention on how to resize a stacklayoupanel to fit its elements. There are properties that allow resizing to fit its elements; however, these properties are not working for me. I was wondering if there was anyone on here who has used this and can help me out. I have a list view that has listViewVisualItems that do not fit their contents. Rather the contents "leak" out of the visual items below and bleed into the next one. Here is my custom item class.</p> <pre><code>public class ChargePlotListViewItem : SimpleListViewVisualItem { private LightVisualElement imageElement; private LightVisualElement titleElement; private LightVisualElement bioElement; private StackLayoutPanel stackLayout; protected override void CreateChildElements() { base.CreateChildElements(); stackLayout = new StackLayoutPanel(); stackLayout.Orientation = System.Windows.Forms.Orientation.Vertical; //stackLayout.AutoSize = true; These do not work //stackLayout.AutoSizeMode = RadAutoSizeMode.WrapAroundChildren; imageElement = new LightVisualElement(); imageElement.DrawText = false; imageElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom; //imageElement.StretchVertically = false; imageElement.Margin = new System.Windows.Forms.Padding(1, 1, 1, 2); imageElement.ShouldHandleMouseInput = false; imageElement.NotifyParentOnMouseInput = true; imageElement.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize; //stackLayout.Children.Add(imageElement); titleElement = new LightVisualElement(); titleElement.TextAlignment = ContentAlignment.TopCenter; titleElement.Margin = new Padding(2, 1, 1, 2); titleElement.Font = new System.Drawing.Font("Segoe UI", 8, FontStyle.Italic, GraphicsUnit.Point); titleElement.ShouldHandleMouseInput = false; titleElement.NotifyParentOnMouseInput = true; stackLayout.Children.Add(titleElement); bioElement = new LightVisualElement(); bioElement.TextAlignment = ContentAlignment.BottomLeft; bioElement.ShouldHandleMouseInput = false; bioElement.NotifyParentOnMouseInput = true; bioElement.Margin = new Padding(2, 1, 1, 2); bioElement.Font = new System.Drawing.Font("Segoe UI", 9, FontStyle.Regular, GraphicsUnit.Point); bioElement.ForeColor = Color.FromArgb(255, 114, 118, 125); stackLayout.Children.Add(bioElement); this.Children.Add(stackLayout); //this.stackLayout.Measure(new System.Drawing.SizeF((float)stackLayout.Size.Width, (float)20)); this.Padding = new Padding(1, 2, 1, 2); this.Shape = new RoundRectShape(3); this.BorderColor = Color.Black; this.BorderGradientStyle = GradientStyles.Solid; this.DrawBorder = true; this.DrawFill = true; this.BackColor = Color.Azure; this.GradientStyle = GradientStyles.Solid; } protected override void SynchronizeProperties() { base.SynchronizeProperties(); frmBingMaps.CriminalPlotObject plotObject = this.Data.Value as frmBingMaps.CriminalPlotObject; if (plotObject != null) { try { this.imageElement.Image = Crime_Information_System.Properties.Resources .bullet_blue; } catch { } //building the title for the element depending on which names are on record StringBuilder NameBuilder = new StringBuilder(); if (plotObject.Data.FirstName != null | plotObject.Data.FirstName != string.Empty) NameBuilder.Append(plotObject.Data.FirstName + " "); if (plotObject.Data.LastName != null | plotObject.Data.LastName != string.Empty) NameBuilder.Append(plotObject.Data.LastName + " "); //NameBuilder.Append(" Charge: " + gangBanger.Incidents[0].Charges[0].ChargeDescription); this.titleElement.Text = NameBuilder.ToString(); StringBuilder BioBuilder = new StringBuilder(); //this.radDesktopAlert1.ContentText = "&lt;html&gt;&lt;b&gt;" + CentralDataStore.AllUsers.Find(P =&gt; P.intUserID // == BLAH.SenderID).strFirstName + " " + CentralDataStore.AllUsers.Find(P =&gt; P.intUserID == // BLAH.SenderID).strLastName + "&lt;/b&gt;&lt;br&gt;" + BLAH.Subject; BioBuilder.Append("&lt;html&gt;"); BioBuilder.Append("&lt;b&gt;Incident ID&lt;/b&gt;: " + plotObject.Data.Incidents.Find( P =&gt; P.IncidentID == plotObject.CaseID).IncidentID.ToString()); BioBuilder.Append("&lt;br&gt;"); BioBuilder.Append("&lt;b&gt;Date&lt;/b&gt;: " + plotObject.Data.Incidents.Find( P =&gt; P.IncidentID == plotObject.CaseID).DateOfIncident.ToShortDateString()); BioBuilder.Append("&lt;br&gt;"); BioBuilder.Append(plotObject.Data.Incidents.Find(P =&gt; P.IncidentID == plotObject .CaseID).Description); BioBuilder.Append("&lt;br&gt;"); //BioBuilder.Append("\r\n"); BioBuilder.Append("&lt;b&gt;Location&lt;/b&gt;: "); BioBuilder.Append(plotObject.Data.Incidents.Find(P =&gt; P.IncidentID == plotObject.CaseID).Location); BioBuilder.Append("&lt;br&gt;"); //BioBuilder.Append("\r\n"); BioBuilder.Append(string.Format("&lt;b&gt;Charges&lt;/b&gt;: ")); foreach (Charge c in plotObject.Data.Incidents.Find(P =&gt; P.IncidentID == plotObject.CaseID ).Charges) { BioBuilder.Append(c.ChargeDescription + ", "); } BioBuilder.Remove(BioBuilder.Length - 2,2); //BioBuilder.Append(" bioElement.Text = BioBuilder.ToString(); this.Text = ""; //here to erase the system.crimesysteminformation.plot blah object name } } protected override Type ThemeEffectiveType { get { return typeof(IconListViewVisualItem); } } protected override SizeF MeasureOverride(SizeF availableSize) { SizeF measuredSize = base.MeasureOverride(availableSize); this.stackLayout.Measure(measuredSize); return measuredSize; } protected override SizeF ArrangeOverride(SizeF finalSize) { base.ArrangeOverride(finalSize); this.stackLayout.Arrange(new RectangleF(PointF.Empty, finalSize)); return finalSize; } </code></pre>
 

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