public virtual void Measure(Size bounds) { myNeedsMeasure = false; // cap a control's dimensions if desired bounds.Width = Math.Min(bounds.Width, myMaxWidth); bounds.Height = Math.Min(bounds.Height, myMaxHeight); Size newBounds = bounds; if (bounds.Width != Int32.MaxValue) { newBounds.Width = bounds.Width - myMargin.Value.Left - myMargin.Value.Right; } if (bounds.Height != Int32.MaxValue) { newBounds.Height = bounds.Height - myMargin.Value.Top - myMargin.Value.Bottom; } bool boundsChange = myLastMeasureBounds != newBounds; myLastMeasureBounds = newBounds; if (MeasureUnpadded(newBounds, boundsChange)) { WindowlessControlHost.WindowlessInvalidate(this); } }
void WindowlessInvalidate(Rectangle rect) { PrepareDirtyRegion(); myDirtyRegion.Union(rect); Invalidate(rect); // tell all child controls that are transparent and in this rect that they need to repaint foreach (Control control in Controls) { WindowlessControlHost wc = control as WindowlessControlHost; if (wc == null || wc.BackColor != Color.Transparent) { continue; } Rectangle intersect = new Rectangle(wc.Left, wc.Top, wc.Width, wc.Height); intersect.Intersect(rect); if (intersect.Width == 0 || intersect.Height == 0) { continue; } intersect.X -= wc.Left; intersect.Y -= wc.Top; wc.WindowlessInvalidate(intersect); } }
void RectangleWidthChanged(object sender, DependencyPropertyEventArgs e) { myPen.Width = (float)myRectangleWidth.Value; if (!myFilled.Value) { WindowlessControlHost.WindowlessInvalidate(this); } }
void BottomRightColorChanged(object sender, DependencyPropertyEventArgs e) { myVertices[1].Red = (ushort)(myBottomRightColor.Value.R << 8); myVertices[1].Green = (ushort)(myBottomRightColor.Value.G << 8); myVertices[1].Blue = (ushort)(myBottomRightColor.Value.B << 8); myVertices[1].Alpha = (ushort)(myBottomRightColor.Value.A << 8); WindowlessControlHost.WindowlessInvalidate(this); }
public static void WindowlessInvalidate(IWindowlessControl sender) { Point origin = Point.Empty; IWindowlessControl parent = sender; while (!(parent is WindowlessControlHost) && parent != null) { origin.X += parent.Left; origin.Y += parent.Top; parent = parent.Parent; } WindowlessControlHost host = parent as WindowlessControlHost; if (host != null) { host.WindowlessInvalidate(new Rectangle(origin.X, origin.Y, sender.Width, sender.Height)); } }
void BitmapChanged(object sender, DependencyPropertyEventArgs e) { PlatformBitmap oldBitmap = e.OldValue as PlatformBitmap; PlatformBitmap newBitmap = e.NewValue as PlatformBitmap; Size originalSize = Size.Empty; if (oldBitmap != null) { originalSize = new Size(oldBitmap.Width, oldBitmap.Height); } Size newSize = Size.Empty; if (newBitmap != null) { newSize = new Size(newBitmap.Width, newBitmap.Height); } if (originalSize != newSize) { Remeasure(); } WindowlessControlHost.WindowlessInvalidate(this); }
void ForeColorChanged(object sender, DependencyPropertyEventArgs e) { myForeBrush.Color = ForeColor; WindowlessControlHost.WindowlessInvalidate(this); }
protected virtual void FontChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); Remeasure(); WindowlessControlHost.WindowlessInvalidate(this); }
void VerticalTextAlignmentChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); }
void MultilineChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); }
void AutoEllipsisChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); }
void MarginChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); Remeasure(); }
void ClipToBoundsChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); }
void PaintChildrenChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); }
void GradientDirectionChanged(object sender, DependencyPropertyEventArgs e) { WindowlessControlHost.WindowlessInvalidate(this); }