By setting the Height property on the WrapPanel to the height of the ScrollContentPresenter, it will never scroll vertically. However, if you remove that Binding, it will never wrap, since in the layout pass, it has infinite height to layout in I would suggest creating your own panel class to get the behavior you want. Have a separate dependency property that you can bind the desired height to, so you can use that to calculate the target height in the measure and arrange steps.
If any one child is taller than the desired height, use that child's height as the target height to calculate the wrapping Here is an example panel to do this: public class SmartWrapPanel : WrapPanel { /// /// Identifies the DesiredHeight dependency property /// public static readonly DependencyProperty DesiredHeightProperty = DependencyProperty. Register( "DesiredHeight", typeof(double), typeof(SmartWrapPanel), new FrameworkPropertyMetadata(Double. NaN, FrameworkPropertyMetadataOptions.
AffectsArrange | FrameworkPropertyMetadataOptions. AffectsMeasure)); /// /// Gets or sets the height to attempt to be. If any child is taller than this, will use the child's height.
/// public double DesiredHeight { get { return (double)GetValue(DesiredHeightProperty); } set { SetValue(DesiredHeightProperty, value); } } protected override Size MeasureOverride(Size constraint) { Size ret = base. MeasureOverride(constraint); double h = ret. Height; if (!Double.
IsNaN(DesiredHeight)) { h = DesiredHeight; foreach (UIElement child in Children) { if (child.DesiredSize. Height > h) h = child.DesiredSize. Height; } } return new Size(ret.
Width, h); } protected override System.Windows. Size ArrangeOverride(Size finalSize) { double h = finalSize. Height; if (!Double.
IsNaN(DesiredHeight)) { h = DesiredHeight; foreach (UIElement child in Children) { if (child.DesiredSize. Height > h) h = child.DesiredSize. Height; } } return base.
ArrangeOverride(new Size(finalSize. Width, h)); } }.
By setting the Height property on the WrapPanel to the height of the ScrollContentPresenter, it will never scroll vertically. However, if you remove that Binding, it will never wrap, since in the layout pass, it has infinite height to layout in. I would suggest creating your own panel class to get the behavior you want.
Have a separate dependency property that you can bind the desired height to, so you can use that to calculate the target height in the measure and arrange steps. If any one child is taller than the desired height, use that child's height as the target height to calculate the wrapping. Here is an example panel to do this: public class SmartWrapPanel : WrapPanel { /// /// Identifies the DesiredHeight dependency property /// public static readonly DependencyProperty DesiredHeightProperty = DependencyProperty.
Register( "DesiredHeight", typeof(double), typeof(SmartWrapPanel), new FrameworkPropertyMetadata(Double. NaN, FrameworkPropertyMetadataOptions. AffectsArrange | FrameworkPropertyMetadataOptions.
AffectsMeasure)); /// /// Gets or sets the height to attempt to be. If any child is taller than this, will use the child's height. /// public double DesiredHeight { get { return (double)GetValue(DesiredHeightProperty); } set { SetValue(DesiredHeightProperty, value); } } protected override Size MeasureOverride(Size constraint) { Size ret = base.
MeasureOverride(constraint); double h = ret. Height; if (!Double. IsNaN(DesiredHeight)) { h = DesiredHeight; foreach (UIElement child in Children) { if (child.DesiredSize.
Height > h) h = child.DesiredSize. Height; } } return new Size(ret. Width, h); } protected override System.Windows.
Size ArrangeOverride(Size finalSize) { double h = finalSize. Height; if (!Double. IsNaN(DesiredHeight)) { h = DesiredHeight; foreach (UIElement child in Children) { if (child.DesiredSize.
Height > h) h = child.DesiredSize. Height; } } return base. ArrangeOverride(new Size(finalSize.
Width, h)); } }.
This is almost the exact solution I need. It allows the vertical scrolling to occur, but stop horizontal scrolling. I modified it slightly (modified code shown in the next answer), and it works perfectly.
Thanks, Abe. – mike Sep 17 '08 at 12:42.
Here is the slightly modified code - all credit given to Abe Heidebrecht, who previously posted it - that allows both horizontal and vertical scrolling. The only change is that the return value of MeasureOverride needs to be base. MeasureOverride(new Size(ret.
Width, h)). // Original code : Abe Heidebrecht public class SmartWrapPanel : WrapPanel { /// /// Identifies the DesiredHeight dependency property /// public static readonly DependencyProperty DesiredHeightProperty = DependencyProperty. Register( "DesiredHeight", typeof(double), typeof(SmartWrapPanel), new FrameworkPropertyMetadata(Double.
NaN, FrameworkPropertyMetadataOptions. AffectsArrange | FrameworkPropertyMetadataOptions. AffectsMeasure)); /// /// Gets or sets the height to attempt to be.
If any child is taller than this, will use the child's height. /// public double DesiredHeight { get { return (double)GetValue(DesiredHeightProperty); } set { SetValue(DesiredHeightProperty, value); } } protected override Size MeasureOverride(Size constraint) { Size ret = base. MeasureOverride(constraint); double h = ret.
Height; if (!Double. IsNaN(DesiredHeight)) { h = DesiredHeight; foreach (UIElement child in Children) { if (child.DesiredSize. Height > h) h = child.DesiredSize.
Height; } } return base. MeasureOverride(new Size(ret. Width, h)); } protected override System.Windows.
Size ArrangeOverride(Size finalSize) { double h = finalSize. Height; if (!Double. IsNaN(DesiredHeight)) { h = DesiredHeight; foreach (UIElement child in Children) { if (child.DesiredSize.
Height > h) h = child.DesiredSize. Height; } } return base. ArrangeOverride(new Size(finalSize.
Width, h)); } }.
I would think that you are correct that it has to do with the binding. What happens when you remove the binding? With the binding are you trying to fill up at least the entire height of the list box?
If so, consider binding to MinHeight instead, or try using the VerticalAlignment property.
Thanks for answering, David. When the binding is removed, no wrapping occurs. The WrapPanel puts every group into a single vertical column.
The binding is meant to force the WrapPanel to actually wrap. If no binding is set, the WrapPanel assumes the height is infinite and never wraps. Binding to MinHeight results in an empty listbox.
I can see how the VerticalAlignment property could seem to be a solution, but alignment itself prevents any wrapping from occurring. When binding and alignment are used together, the alignment has no effect on the problem.
By setting the Height property on the WrapPanel to the height of the ScrollContentPresenter, it will never scroll vertically. However, if you remove that Binding, it will never wrap, since in the layout pass, it has infinite height to layout in.
Here is the slightly modified code - all credit given to Abe Heidebrecht, who previously posted it - that allows both horizontal and vertical scrolling. The only change is that the return value of MeasureOverride needs to be base. MeasureOverride(new Size(ret.
Width, h)).
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.