Exemplo n.º 1
0
      /// <summary/>
      public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
         if (value == null) {
            throw new ArgumentNullException("value");
         }
         string plcString = value as string;
         if (plcString.IsEmpty()) {
            return base.ConvertFrom(context, culture, value);
         }

         try {
            var plc = new Placement();
            foreach (var token in _placementTokenizer(plcString)) {
               var key = token.Key;
               var val = token.Value;
               if (key.IsEmpty() && val == "center") {
                  plc.Dock = DockPosition.Float;
                  plc.Anchor = AnchorPoint.Center;
               } else if (key.IsEmpty() || key == "dock") {
                  plc.Dock = (DockPosition)Enum.Parse(typeof(DockPosition), val, true);
               } else if (key == "anchor") {
                  plc.Anchor = (AnchorPoint)Enum.Parse(typeof(AnchorPoint), val, true);
               } else if (key == "margin") {
                  plc.Margin = (Thickness)_thicknessConverter.ConvertFrom(context, culture, val);
               } else if (key == "size") {
                  var size = (Size)_sizeConverter.ConvertFrom(context, culture, val);
                  plc.MinWidth = plc.MaxWidth = size.Width;
                  plc.MinHeight = plc.MaxHeight = size.Height;
               } else if (key == "minsize") {
                  var size = (Size)_sizeConverter.ConvertFrom(context, culture, val);
                  plc.MinWidth = size.Width;
                  plc.MinHeight = size.Height;
               } else if (key == "maxsize") {
                  var size = (Size)_sizeConverter.ConvertFrom(context, culture, val);
                  plc.MaxWidth = size.Width;
                  plc.MaxHeight = size.Height;
               } else if (key == "height") {
                  plc.MinHeight = plc.MaxHeight = Double.Parse(val);
               } else if (key == "minheight") {
                  plc.MinHeight = Double.Parse(val);
               } else if (key == "maxheight") {
                  plc.MaxHeight = Double.Parse(val);
               } else if (key == "width") {
                  plc.MinWidth = plc.MaxWidth = Double.Parse(val);
               } else if (key == "minwidth") {
                  plc.MinWidth = Double.Parse(val);
               } else if (key == "maxwidth") {
                  plc.MaxWidth = Double.Parse(val);
               } else if (key == "bidi") {
                  plc.Bidi = (BidiPlacement)Enum.Parse(typeof(BidiPlacement), val, true);
               } else if (key == "zindex") {
                  plc.ZIndex = Int32.Parse(val);
               }
            }
            return plc;
         } catch (Exception e) {
            throw new InvalidCastException("Invalid placement string format: '{0}'.".Substitute(plcString), e);
         }
      }
Exemplo n.º 2
0
 /// <summary>Creates a frozen <see cref="Placement"/> instance from the given parameters.</summary>
 public static Placement CreateFrozen(DockPosition dock, AnchorPoint anchor, Thickness margin, Size size) {
    var p = new Placement { Dock = dock, Anchor = anchor, Margin = margin };
    p.SetFixedSize(size);
    p.Freeze();
    return p;
 }
Exemplo n.º 3
0
 /// <summary>Creates a frozen <see cref="Placement"/> instance from the given parameters.</summary>
 public static Placement CreateFrozen(DockPosition dock, Thickness margin) {
    var p = new Placement { Dock = dock, Margin = margin };
    p.Freeze();
    return p;
 }
Exemplo n.º 4
0
 /// <summary>Creates a frozen <see cref="Placement"/> instance from the given parameters.</summary>
 public static Placement CreateFrozen(DockPosition dock, AnchorPoint anchor) {
    var p = new Placement { Dock = dock, Anchor = anchor };
    p.Freeze();
    return p;
 }
Exemplo n.º 5
0
 /// <summary>Creates a frozen <see cref="Placement"/> instance from the given parameters.</summary>
 public static Placement CreateFrozen(DockPosition dock) {
    var p = new Placement { Dock = dock };
    p.Freeze();
    return p;
 }
Exemplo n.º 6
0
      /// <summary>Coerces a <see cref="Placement"/> instance according to specified flow direction.</summary>
      public static Placement CoerceDirection(Placement placement, FlowDirection flowDirection) {
         if (placement == null || placement.Bidi == BidiPlacement.Ignore || flowDirection != FlowDirection.RightToLeft) {
            return placement;
         }
         var changed = false;
         
         var dock = placement.Dock;
         if (dock == DockPosition.Left) {
            dock = DockPosition.Right;
            changed = true;
         } else if (dock == DockPosition.Right) {
            dock = DockPosition.Left;
            changed = true;
         }

         var anchor = placement.Anchor;
         if ((anchor & AnchorPoint.Left) != 0) {
            anchor = (anchor & ~AnchorPoint.Left) | AnchorPoint.Right;
            changed = true;
         } else if ((anchor & AnchorPoint.Right) != 0) {
            anchor = (anchor & ~AnchorPoint.Right) | AnchorPoint.Left;
            changed = true;
         }

         var margin = placement.Margin;
         if (margin.Left != margin.Right) {
            margin = new Thickness(margin.Right, margin.Top, margin.Left, margin.Bottom);
            changed = true;
         }

         if (changed) {
            var placement2 = (Placement)placement.Clone();
            placement2.Dock = dock;
            placement2.Anchor = anchor;
            placement2.Margin = margin;
            placement2.Freeze();
            return placement2;
         } else {
            return placement;
         }
      }