Created
October 11, 2010 12:07
-
-
Save robfe/620425 to your computer and use it in GitHub Desktop.
Path subclass for drawing a line that fills its available space in silverlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FillingLine : Path | |
{ | |
Size lastFinalSize; | |
protected override Size MeasureOverride(Size availableSize) | |
{ | |
return new Size(0, 0); | |
} | |
protected override Size ArrangeOverride(Size finalSize) | |
{ | |
// track the last size so that we don't re-calculate when we don't need to. | |
// this is especially important since setting the Data triggers a new layout! | |
if (lastFinalSize != finalSize) | |
{ | |
lastFinalSize = finalSize; | |
Data = CreatePathData(finalSize); | |
} | |
return finalSize; | |
} | |
static PathGeometry CreatePathData(Size size) | |
{ | |
Rect rect; | |
if (size.Height == 1) | |
{ | |
rect = new Rect(0, 0.5, size.Width, 0); | |
} | |
else if (size.Width == 1) | |
{ | |
rect = new Rect(0.5, 0, 0, size.Height); | |
} | |
else | |
{ | |
rect = new Rect(0.5, 0.5, size.Width - 0.5, size.Height - 0.5); | |
} | |
return new PathGeometry | |
{ | |
Figures = | |
{ | |
new PathFigure | |
{ | |
StartPoint = new Point(rect.Left, rect.Top), | |
Segments = | |
{ | |
new LineSegment {Point = new Point(rect.Right, rect.Bottom)} | |
} | |
} | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment