Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Controls / WrapPanel.cs / 1 / WrapPanel.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: WrapPanel.cs
//
// Description: Contains the WrapPanel class.
// Spec at http://avalon/layout/Specs/WrapPanel.xml
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Utility;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Threading;
using System.Windows.Media;
using System;
namespace System.Windows.Controls
{
///
/// WrapPanel is used to place child UIElements at sequential positions from left to the right
/// and then "wrap" the lines of children from top to the bottom.
///
/// All children get the layout partition of size ItemWidth x ItemHeight.
///
///
public class WrapPanel : Panel
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Default constructor
///
public WrapPanel() : base()
{
_orientation = (Orientation) OrientationProperty.GetDefaultValue(DependencyObjectType);
}
#endregion
//--------------------------------------------------------------------
//
// Public Methods
//
//-------------------------------------------------------------------
#region Public Methods
#endregion
//--------------------------------------------------------------------
//
// Public Properties + Dependency Properties's
//
//--------------------------------------------------------------------
#region Public Properties
private static bool IsWidthHeightValid(object value)
{
double v = (double)value;
return (DoubleUtil.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v));
}
///
/// DependencyProperty for property.
///
public static readonly DependencyProperty ItemWidthProperty =
DependencyProperty.Register(
"ItemWidth",
typeof(double),
typeof(WrapPanel),
new FrameworkPropertyMetadata(
Double.NaN,
FrameworkPropertyMetadataOptions.AffectsMeasure),
new ValidateValueCallback(IsWidthHeightValid));
///
/// The ItemWidth and ItemHeight properties specify the size of all items in the WrapPanel.
/// Note that children of
/// WrapPanel may have their own Width/Height properties set - the ItemWidth/ItemHeight
/// specifies the size of "layout partition" reserved by WrapPanel for the child.
/// If this property is not set (or set to "Auto" in markup or Double.NaN in code) - the size of layout
/// partition is equal to DesiredSize of the child element.
///
[TypeConverter(typeof(LengthConverter))]
public double ItemWidth
{
get { return (double) GetValue(ItemWidthProperty); }
set { SetValue(ItemWidthProperty, value); }
}
///
/// DependencyProperty for property.
///
public static readonly DependencyProperty ItemHeightProperty =
DependencyProperty.Register(
"ItemHeight",
typeof(double),
typeof(WrapPanel),
new FrameworkPropertyMetadata(
Double.NaN,
FrameworkPropertyMetadataOptions.AffectsMeasure),
new ValidateValueCallback(IsWidthHeightValid));
///
/// The ItemWidth and ItemHeight properties specify the size of all items in the WrapPanel.
/// Note that children of
/// WrapPanel may have their own Width/Height properties set - the ItemWidth/ItemHeight
/// specifies the size of "layout partition" reserved by WrapPanel for the child.
/// If this property is not set (or set to "Auto" in markup or Double.NaN in code) - the size of layout
/// partition is equal to DesiredSize of the child element.
///
[TypeConverter(typeof(LengthConverter))]
public double ItemHeight
{
get { return (double) GetValue(ItemHeightProperty); }
set { SetValue(ItemHeightProperty, value); }
}
///
/// DependencyProperty for property.
///
public static readonly DependencyProperty OrientationProperty =
StackPanel.OrientationProperty.AddOwner(
typeof(WrapPanel),
new FrameworkPropertyMetadata(
Orientation.Horizontal,
FrameworkPropertyMetadataOptions.AffectsMeasure,
new PropertyChangedCallback(OnOrientationChanged)));
///
/// Specifies dimension of children positioning in absence of wrapping.
/// Wrapping occurs in orthogonal direction. For example, if Orientation is Horizontal,
/// the items try to form horizontal rows first and if needed are wrapped and form vertical stack of rows.
/// If Orientation is Vertical, items first positioned in a vertical column, and if there is
/// not enough space - wrapping creates additional columns in horizontal dimension.
///
public Orientation Orientation
{
get { return _orientation; }
set { SetValue(OrientationProperty, value); }
}
///
///
///
private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
WrapPanel p = (WrapPanel)d;
p._orientation = (Orientation) e.NewValue;
}
private Orientation _orientation;
#endregion
//-------------------------------------------------------------------
//
// Protected Methods
//
//--------------------------------------------------------------------
#region Protected Methods
private struct UVSize
{
internal UVSize (Orientation orientation, double width, double height)
{
U = V = 0d;
_orientation = orientation;
Width = width;
Height = height;
}
internal UVSize (Orientation orientation)
{
U = V = 0d;
_orientation = orientation;
}
internal double U;
internal double V;
private Orientation _orientation;
internal double Width
{
get { return (_orientation == Orientation.Horizontal ? U : V); }
set { if(_orientation == Orientation.Horizontal) U = value; else V = value; }
}
internal double Height
{
get { return (_orientation == Orientation.Horizontal ? V : U); }
set { if(_orientation == Orientation.Horizontal) V = value; else U = value; }
}
}
///
///
///
protected override Size MeasureOverride(Size constraint)
{
UVSize curLineSize = new UVSize(Orientation);
UVSize panelSize = new UVSize(Orientation);
UVSize uvConstraint = new UVSize(Orientation, constraint.Width, constraint.Height);
double itemWidth = ItemWidth;
double itemHeight = ItemHeight;
bool itemWidthSet = !DoubleUtil.IsNaN(itemWidth);
bool itemHeightSet = !DoubleUtil.IsNaN(itemHeight);
Size childConstraint = new Size(
(itemWidthSet ? itemWidth : constraint.Width),
(itemHeightSet ? itemHeight : constraint.Height));
UIElementCollection children = InternalChildren;
for(int i=0, count = children.Count; i
///
///
protected override Size ArrangeOverride(Size finalSize)
{
int firstInLine = 0;
double itemWidth = ItemWidth;
double itemHeight = ItemHeight;
double accumulatedV = 0;
double itemU = (Orientation == Orientation.Horizontal ? itemWidth : itemHeight);
UVSize curLineSize = new UVSize(Orientation);
UVSize uvFinalSize = new UVSize(Orientation, finalSize.Width, finalSize.Height);
bool itemWidthSet = !DoubleUtil.IsNaN(itemWidth);
bool itemHeightSet = !DoubleUtil.IsNaN(itemHeight);
bool useItemU = (Orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet);
UIElementCollection children = InternalChildren;
for(int i=0, count = children.Count; i
/// WrapPanel is used to place child UIElements at sequential positions from left to the right
/// and then "wrap" the lines of children from top to the bottom.
///
/// All children get the layout partition of size ItemWidth x ItemHeight.
///
///
public class WrapPanel : Panel
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Default constructor
///
public WrapPanel() : base()
{
_orientation = (Orientation) OrientationProperty.GetDefaultValue(DependencyObjectType);
}
#endregion
//--------------------------------------------------------------------
//
// Public Methods
//
//-------------------------------------------------------------------
#region Public Methods
#endregion
//--------------------------------------------------------------------
//
// Public Properties + Dependency Properties's
//
//--------------------------------------------------------------------
#region Public Properties
private static bool IsWidthHeightValid(object value)
{
double v = (double)value;
return (DoubleUtil.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v));
}
///
/// DependencyProperty for property.
///
public static readonly DependencyProperty ItemWidthProperty =
DependencyProperty.Register(
"ItemWidth",
typeof(double),
typeof(WrapPanel),
new FrameworkPropertyMetadata(
Double.NaN,
FrameworkPropertyMetadataOptions.AffectsMeasure),
new ValidateValueCallback(IsWidthHeightValid));
///
/// The ItemWidth and ItemHeight properties specify the size of all items in the WrapPanel.
/// Note that children of
/// WrapPanel may have their own Width/Height properties set - the ItemWidth/ItemHeight
/// specifies the size of "layout partition" reserved by WrapPanel for the child.
/// If this property is not set (or set to "Auto" in markup or Double.NaN in code) - the size of layout
/// partition is equal to DesiredSize of the child element.
///
[TypeConverter(typeof(LengthConverter))]
public double ItemWidth
{
get { return (double) GetValue(ItemWidthProperty); }
set { SetValue(ItemWidthProperty, value); }
}
///
/// DependencyProperty for property.
///
public static readonly DependencyProperty ItemHeightProperty =
DependencyProperty.Register(
"ItemHeight",
typeof(double),
typeof(WrapPanel),
new FrameworkPropertyMetadata(
Double.NaN,
FrameworkPropertyMetadataOptions.AffectsMeasure),
new ValidateValueCallback(IsWidthHeightValid));
///
/// The ItemWidth and ItemHeight properties specify the size of all items in the WrapPanel.
/// Note that children of
/// WrapPanel may have their own Width/Height properties set - the ItemWidth/ItemHeight
/// specifies the size of "layout partition" reserved by WrapPanel for the child.
/// If this property is not set (or set to "Auto" in markup or Double.NaN in code) - the size of layout
/// partition is equal to DesiredSize of the child element.
///
[TypeConverter(typeof(LengthConverter))]
public double ItemHeight
{
get { return (double) GetValue(ItemHeightProperty); }
set { SetValue(ItemHeightProperty, value); }
}
///
/// DependencyProperty for property.
///
public static readonly DependencyProperty OrientationProperty =
StackPanel.OrientationProperty.AddOwner(
typeof(WrapPanel),
new FrameworkPropertyMetadata(
Orientation.Horizontal,
FrameworkPropertyMetadataOptions.AffectsMeasure,
new PropertyChangedCallback(OnOrientationChanged)));
///
/// Specifies dimension of children positioning in absence of wrapping.
/// Wrapping occurs in orthogonal direction. For example, if Orientation is Horizontal,
/// the items try to form horizontal rows first and if needed are wrapped and form vertical stack of rows.
/// If Orientation is Vertical, items first positioned in a vertical column, and if there is
/// not enough space - wrapping creates additional columns in horizontal dimension.
///
public Orientation Orientation
{
get { return _orientation; }
set { SetValue(OrientationProperty, value); }
}
///
///
///
private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
WrapPanel p = (WrapPanel)d;
p._orientation = (Orientation) e.NewValue;
}
private Orientation _orientation;
#endregion
//-------------------------------------------------------------------
//
// Protected Methods
//
//--------------------------------------------------------------------
#region Protected Methods
private struct UVSize
{
internal UVSize (Orientation orientation, double width, double height)
{
U = V = 0d;
_orientation = orientation;
Width = width;
Height = height;
}
internal UVSize (Orientation orientation)
{
U = V = 0d;
_orientation = orientation;
}
internal double U;
internal double V;
private Orientation _orientation;
internal double Width
{
get { return (_orientation == Orientation.Horizontal ? U : V); }
set { if(_orientation == Orientation.Horizontal) U = value; else V = value; }
}
internal double Height
{
get { return (_orientation == Orientation.Horizontal ? V : U); }
set { if(_orientation == Orientation.Horizontal) V = value; else U = value; }
}
}
///
///
///
protected override Size MeasureOverride(Size constraint)
{
UVSize curLineSize = new UVSize(Orientation);
UVSize panelSize = new UVSize(Orientation);
UVSize uvConstraint = new UVSize(Orientation, constraint.Width, constraint.Height);
double itemWidth = ItemWidth;
double itemHeight = ItemHeight;
bool itemWidthSet = !DoubleUtil.IsNaN(itemWidth);
bool itemHeightSet = !DoubleUtil.IsNaN(itemHeight);
Size childConstraint = new Size(
(itemWidthSet ? itemWidth : constraint.Width),
(itemHeightSet ? itemHeight : constraint.Height));
UIElementCollection children = InternalChildren;
for(int i=0, count = children.Count; i
///
///
protected override Size ArrangeOverride(Size finalSize)
{
int firstInLine = 0;
double itemWidth = ItemWidth;
double itemHeight = ItemHeight;
double accumulatedV = 0;
double itemU = (Orientation == Orientation.Horizontal ? itemWidth : itemHeight);
UVSize curLineSize = new UVSize(Orientation);
UVSize uvFinalSize = new UVSize(Orientation, finalSize.Width, finalSize.Height);
bool itemWidthSet = !DoubleUtil.IsNaN(itemWidth);
bool itemHeightSet = !DoubleUtil.IsNaN(itemHeight);
bool useItemU = (Orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet);
UIElementCollection children = InternalChildren;
for(int i=0, count = children.Count; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DbExpressionVisitor_TResultType.cs
- TextBoxBase.cs
- XamlFilter.cs
- UnionQueryOperator.cs
- DispatcherTimer.cs
- ZoneLinkButton.cs
- Util.cs
- Binding.cs
- DefaultTextStoreTextComposition.cs
- BamlTreeMap.cs
- StickyNoteContentControl.cs
- AlignmentXValidation.cs
- HwndSourceKeyboardInputSite.cs
- BaseHashHelper.cs
- VirtualizingPanel.cs
- MenuItemStyleCollectionEditor.cs
- FontStretch.cs
- DocumentOutline.cs
- Roles.cs
- PreviewPageInfo.cs
- InternalConfigEventArgs.cs
- OpenTypeLayout.cs
- GridViewColumn.cs
- IUnknownConstantAttribute.cs
- BitmapEffectInput.cs
- WizardForm.cs
- AsyncResult.cs
- SkinBuilder.cs
- EdmToObjectNamespaceMap.cs
- RemotingException.cs
- TransportBindingElementImporter.cs
- DictionaryBase.cs
- XPathEmptyIterator.cs
- CodeCommentStatementCollection.cs
- Operator.cs
- RoleManagerModule.cs
- XmlIterators.cs
- LogSwitch.cs
- XmlSchemaAnyAttribute.cs
- HtmlHead.cs
- EditorPartChrome.cs
- LayoutInformation.cs
- CalendarDay.cs
- _ConnectOverlappedAsyncResult.cs
- PtsHost.cs
- _LoggingObject.cs
- MetadataArtifactLoaderComposite.cs
- Automation.cs
- RuntimeTrackingProfile.cs
- SHA1CryptoServiceProvider.cs
- StringWriter.cs
- IntAverageAggregationOperator.cs
- HtmlWindow.cs
- CompilerScope.Storage.cs
- SQLInt64Storage.cs
- HtmlInputReset.cs
- SqlParameterizer.cs
- BindingNavigator.cs
- NumericUpDownAcceleration.cs
- PreservationFileReader.cs
- InputLanguageSource.cs
- ViewManagerAttribute.cs
- TextBox.cs
- OdbcInfoMessageEvent.cs
- ShapingEngine.cs
- SqlSelectClauseBuilder.cs
- _AutoWebProxyScriptEngine.cs
- LocalizabilityAttribute.cs
- DataGridViewCellStyleEditor.cs
- BaseTemplateParser.cs
- GridEntry.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- NetworkInformationException.cs
- _LocalDataStore.cs
- TaskbarItemInfo.cs
- AdPostCacheSubstitution.cs
- FSWPathEditor.cs
- WebHttpSecurityElement.cs
- DuplicateWaitObjectException.cs
- JapaneseCalendar.cs
- FontFamilyIdentifier.cs
- Configuration.cs
- SqlGenericUtil.cs
- XmlConvert.cs
- ISAPIWorkerRequest.cs
- AudioStateChangedEventArgs.cs
- DBSqlParserColumn.cs
- ConnectionPointCookie.cs
- HtmlTextArea.cs
- _Win32.cs
- WindowsTooltip.cs
- SeekStoryboard.cs
- DataGridItem.cs
- CodeSubDirectoriesCollection.cs
- IPGlobalProperties.cs
- Win32KeyboardDevice.cs
- DES.cs
- DataGridViewColumnConverter.cs
- SelectedDatesCollection.cs
- DrawingVisual.cs