27 changed files with 1474 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Path.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls.Shapes |
|||
{ |
|||
using System; |
|||
using Perspex.Media; |
|||
|
|||
public class Path : Shape |
|||
{ |
|||
public static readonly PerspexProperty<Geometry> DataProperty = |
|||
PerspexProperty.Register<Path, Geometry>("Data"); |
|||
|
|||
public Geometry Data |
|||
{ |
|||
get { return this.GetValue(DataProperty); } |
|||
set { this.SetValue(DataProperty, value); } |
|||
} |
|||
|
|||
public override Geometry DefiningGeometry |
|||
{ |
|||
get { return this.Data; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Rectangle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls.Shapes |
|||
{ |
|||
using Perspex.Media; |
|||
|
|||
public class Rectangle : Shape |
|||
{ |
|||
private Geometry geometry; |
|||
|
|||
private Size geometrySize; |
|||
|
|||
public override Geometry DefiningGeometry |
|||
{ |
|||
get |
|||
{ |
|||
if (this.geometry == null || this.geometrySize != this.ActualSize) |
|||
{ |
|||
this.geometry = new RectangleGeometry(new Rect(0, 0, this.ActualSize.Width, this.ActualSize.Height)); |
|||
this.geometrySize = this.ActualSize; |
|||
} |
|||
|
|||
return this.geometry; |
|||
} |
|||
} |
|||
|
|||
protected override Size MeasureOverride(Size availableSize) |
|||
{ |
|||
return new Size(this.StrokeThickness, this.StrokeThickness); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,139 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Shape.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls.Shapes |
|||
{ |
|||
using System; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
|
|||
public abstract class Shape : Control |
|||
{ |
|||
public static readonly PerspexProperty<Brush> FillProperty = |
|||
PerspexProperty.Register<Shape, Brush>("Fill"); |
|||
|
|||
public static readonly PerspexProperty<Stretch> StretchProperty = |
|||
PerspexProperty.Register<Shape, Stretch>("Stretch"); |
|||
|
|||
public static readonly PerspexProperty<Brush> StrokeProperty = |
|||
PerspexProperty.Register<Shape, Brush>("Stroke"); |
|||
|
|||
public static readonly PerspexProperty<double> StrokeThicknessProperty = |
|||
PerspexProperty.Register<Shape, double>("StrokeThickness"); |
|||
|
|||
public abstract Geometry DefiningGeometry |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public Brush Fill |
|||
{ |
|||
get { return this.GetValue(FillProperty); } |
|||
set { this.SetValue(FillProperty, value); } |
|||
} |
|||
|
|||
public Geometry RenderedGeometry |
|||
{ |
|||
get { return this.DefiningGeometry; } |
|||
} |
|||
|
|||
public Stretch Stretch |
|||
{ |
|||
get { return this.GetValue(StretchProperty); } |
|||
set { this.SetValue(StretchProperty, value); } |
|||
} |
|||
|
|||
public Brush Stroke |
|||
{ |
|||
get { return this.GetValue(StrokeProperty); } |
|||
set { this.SetValue(StrokeProperty, value); } |
|||
} |
|||
|
|||
public double StrokeThickness |
|||
{ |
|||
get { return this.GetValue(StrokeThicknessProperty); } |
|||
set { this.SetValue(StrokeThicknessProperty, value); } |
|||
} |
|||
|
|||
protected override Size MeasureOverride(Size availableSize) |
|||
{ |
|||
Rect shapeBounds = this.RenderedGeometry.GetRenderBounds(this.StrokeThickness); |
|||
double width = this.Width; |
|||
double height = this.Height; |
|||
double desiredX = availableSize.Width; |
|||
double desiredY = availableSize.Height; |
|||
double sx = 0.0; |
|||
double sy = 0.0; |
|||
|
|||
if (double.IsInfinity(availableSize.Width)) |
|||
{ |
|||
desiredX = shapeBounds.Right; |
|||
} |
|||
|
|||
if (double.IsInfinity(availableSize.Height)) |
|||
{ |
|||
desiredY = shapeBounds.Bottom; |
|||
} |
|||
|
|||
if (shapeBounds.Width > 0) |
|||
{ |
|||
sx = desiredX / shapeBounds.Right; |
|||
} |
|||
|
|||
if (shapeBounds.Height > 0) |
|||
{ |
|||
sy = desiredY / shapeBounds.Bottom; |
|||
} |
|||
|
|||
if (double.IsInfinity(availableSize.Width)) |
|||
{ |
|||
sx = sy; |
|||
} |
|||
|
|||
if (double.IsInfinity(availableSize.Height)) |
|||
{ |
|||
sy = sx; |
|||
} |
|||
|
|||
switch (this.Stretch) |
|||
{ |
|||
case Stretch.Uniform: |
|||
sx = sy = Math.Min(sx, sy); |
|||
break; |
|||
case Stretch.UniformToFill: |
|||
sx = sy = Math.Max(sx, sy); |
|||
break; |
|||
case Stretch.Fill: |
|||
if (double.IsInfinity(availableSize.Width)) |
|||
{ |
|||
sx = 1.0; |
|||
} |
|||
|
|||
if (double.IsInfinity(availableSize.Height)) |
|||
{ |
|||
sy = 1.0; |
|||
} |
|||
|
|||
break; |
|||
default: |
|||
sx = sy = 1; |
|||
break; |
|||
} |
|||
|
|||
double finalX = (width > 0) ? width : shapeBounds.Right * sx; |
|||
double finalY = (height > 0) ? height : shapeBounds.Bottom * sy; |
|||
return new Size(finalX, finalY); |
|||
} |
|||
|
|||
public override void Render(IDrawingContext context) |
|||
{ |
|||
if (this.RenderedGeometry != null) |
|||
{ |
|||
context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.RenderedGeometry); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,289 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PathMarkupParser.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
|
|||
public class PathMarkupParser |
|||
{ |
|||
private static readonly Dictionary<char, Command> Commands = new Dictionary<char, Command> |
|||
{ |
|||
{ 'F', Command.FillRule }, |
|||
{ 'f', Command.FillRule }, |
|||
{ 'M', Command.Move }, |
|||
{ 'm', Command.MoveRelative }, |
|||
{ 'L', Command.Line }, |
|||
{ 'l', Command.LineRelative }, |
|||
{ 'H', Command.HorizontalLine }, |
|||
{ 'h', Command.HorizontalLineRelative }, |
|||
{ 'V', Command.VerticalLine }, |
|||
{ 'v', Command.VerticalLineRelative }, |
|||
{ 'C', Command.CubicBezierCurve }, |
|||
{ 'c', Command.CubicBezierCurveRelative }, |
|||
{ 'Z', Command.Close }, |
|||
{ 'z', Command.Close }, |
|||
}; |
|||
|
|||
private StreamGeometry geometry; |
|||
|
|||
private StreamGeometryContext context; |
|||
|
|||
public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context) |
|||
{ |
|||
this.geometry = geometry; |
|||
this.context = context; |
|||
} |
|||
|
|||
private enum Command |
|||
{ |
|||
None, |
|||
FillRule, |
|||
Move, |
|||
MoveRelative, |
|||
Line, |
|||
LineRelative, |
|||
HorizontalLine, |
|||
HorizontalLineRelative, |
|||
VerticalLine, |
|||
VerticalLineRelative, |
|||
CubicBezierCurve, |
|||
CubicBezierCurveRelative, |
|||
Close, |
|||
Eof, |
|||
} |
|||
|
|||
public void Parse(string s) |
|||
{ |
|||
bool openFigure = false; |
|||
|
|||
using (StringReader reader = new StringReader(s)) |
|||
{ |
|||
Command lastCommand = Command.None; |
|||
Command command; |
|||
Point point = new Point(); |
|||
|
|||
while ((command = ReadCommand(reader, lastCommand)) != Command.Eof) |
|||
{ |
|||
switch (command) |
|||
{ |
|||
case Command.FillRule: |
|||
// TODO: Implement.
|
|||
reader.Read(); |
|||
break; |
|||
|
|||
case Command.Move: |
|||
case Command.MoveRelative: |
|||
if (openFigure) |
|||
{ |
|||
this.context.EndFigure(false); |
|||
} |
|||
|
|||
point = ReadPoint(reader); |
|||
this.context.BeginFigure(point, true); |
|||
openFigure = true; |
|||
break; |
|||
|
|||
case Command.Line: |
|||
point = ReadPoint(reader); |
|||
this.context.LineTo(point); |
|||
break; |
|||
|
|||
case Command.LineRelative: |
|||
point = ReadRelativePoint(reader, point); |
|||
this.context.LineTo(point); |
|||
break; |
|||
|
|||
////case Command.HorizontalLine:
|
|||
//// point.X = ReadDouble(reader);
|
|||
//// this.context.LineTo(point, true, false);
|
|||
//// break;
|
|||
|
|||
////case Command.HorizontalLineRelative:
|
|||
//// point.X += ReadDouble(reader);
|
|||
//// this.context.LineTo(point, true, false);
|
|||
//// break;
|
|||
|
|||
////case Command.VerticalLine:
|
|||
//// point.Y = ReadDouble(reader);
|
|||
//// this.context.LineTo(point, true, false);
|
|||
//// break;
|
|||
|
|||
////case Command.VerticalLineRelative:
|
|||
//// point.Y += ReadDouble(reader);
|
|||
//// this.context.LineTo(point, true, false);
|
|||
//// break;
|
|||
|
|||
////case Command.CubicBezierCurve:
|
|||
////{
|
|||
//// Point point1 = ReadPoint(reader);
|
|||
//// Point point2 = ReadPoint(reader);
|
|||
//// point = ReadPoint(reader);
|
|||
//// this.context.BezierTo(point1, point2, point, true, false);
|
|||
//// break;
|
|||
////}
|
|||
|
|||
case Command.Close: |
|||
this.context.EndFigure(true); |
|||
openFigure = false; |
|||
break; |
|||
|
|||
default: |
|||
throw new NotSupportedException("Unsupported command"); |
|||
} |
|||
|
|||
lastCommand = command; |
|||
} |
|||
|
|||
if (openFigure) |
|||
{ |
|||
this.context.EndFigure(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static Command ReadCommand(StringReader reader, Command lastCommand) |
|||
{ |
|||
ReadWhitespace(reader); |
|||
|
|||
int i = reader.Peek(); |
|||
|
|||
if (i == -1) |
|||
{ |
|||
return Command.Eof; |
|||
} |
|||
else |
|||
{ |
|||
char c = (char)i; |
|||
Command command = Command.None; |
|||
|
|||
if (!Commands.TryGetValue(c, out command)) |
|||
{ |
|||
if ((char.IsDigit(c) || c == '.' || c == '+' || c == '-') && |
|||
(lastCommand != Command.None)) |
|||
{ |
|||
return lastCommand; |
|||
} |
|||
else |
|||
{ |
|||
throw new InvalidDataException("Unexpected path command '" + c + "'."); |
|||
} |
|||
} |
|||
|
|||
reader.Read(); |
|||
return command; |
|||
} |
|||
} |
|||
|
|||
private static double ReadDouble(TextReader reader) |
|||
{ |
|||
// TODO: Handle Infinity, NaN and scientific notation.
|
|||
StringBuilder b = new StringBuilder(); |
|||
bool readSign = false; |
|||
bool readPoint = false; |
|||
bool readExponent = false; |
|||
int i; |
|||
|
|||
while ((i = reader.Peek()) != -1) |
|||
{ |
|||
char c = char.ToUpperInvariant((char)i); |
|||
|
|||
if (((c == '+' || c == '-') && !readSign) || |
|||
(c == '.' && !readPoint) || |
|||
(c == 'E' && !readExponent) || |
|||
char.IsDigit(c)) |
|||
{ |
|||
b.Append(c); |
|||
reader.Read(); |
|||
readSign = c == '+' || c == '-'; |
|||
readPoint = c == '.'; |
|||
|
|||
if (c == 'E') |
|||
{ |
|||
readSign = false; |
|||
readExponent = c == 'E'; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return double.Parse(b.ToString()); |
|||
} |
|||
|
|||
private static Point ReadPoint(StringReader reader) |
|||
{ |
|||
ReadWhitespace(reader); |
|||
double x = ReadDouble(reader); |
|||
ReadSeparator(reader); |
|||
double y = ReadDouble(reader); |
|||
return new Point(x, y); |
|||
} |
|||
|
|||
private static Point ReadRelativePoint(StringReader reader, Point lastPoint) |
|||
{ |
|||
ReadWhitespace(reader); |
|||
double x = ReadDouble(reader); |
|||
ReadSeparator(reader); |
|||
double y = ReadDouble(reader); |
|||
return new Point(lastPoint.X + x, lastPoint.Y + y); |
|||
} |
|||
|
|||
private static void ReadSeparator(StringReader reader) |
|||
{ |
|||
int i; |
|||
bool readComma = false; |
|||
|
|||
while ((i = reader.Peek()) != -1) |
|||
{ |
|||
char c = (char)i; |
|||
|
|||
if (char.IsWhiteSpace(c)) |
|||
{ |
|||
reader.Read(); |
|||
} |
|||
else if (c == ',') |
|||
{ |
|||
if (readComma) |
|||
{ |
|||
throw new InvalidDataException("Unexpected ','."); |
|||
} |
|||
|
|||
readComma = true; |
|||
reader.Read(); |
|||
} |
|||
else |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static void ReadWhitespace(StringReader reader) |
|||
{ |
|||
int i; |
|||
|
|||
while ((i = reader.Peek()) != -1) |
|||
{ |
|||
char c = (char)i; |
|||
|
|||
if (char.IsWhiteSpace(c)) |
|||
{ |
|||
reader.Read(); |
|||
} |
|||
else |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="RectangleGeometry.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
using Perspex.Platform; |
|||
using Splat; |
|||
|
|||
public class RectangleGeometry : Geometry |
|||
{ |
|||
public RectangleGeometry(Rect rect) |
|||
{ |
|||
IPlatformRenderInterface factory = Locator.Current.GetService<IPlatformRenderInterface>(); |
|||
IStreamGeometryImpl impl = factory.CreateStreamGeometry(); |
|||
|
|||
using (IStreamGeometryContextImpl context = impl.Open()) |
|||
{ |
|||
context.BeginFigure(rect.TopLeft, true); |
|||
context.LineTo(rect.TopRight); |
|||
context.LineTo(rect.BottomRight); |
|||
context.LineTo(rect.BottomLeft); |
|||
context.EndFigure(true); |
|||
} |
|||
|
|||
this.PlatformImpl = impl; |
|||
} |
|||
|
|||
public override Rect Bounds |
|||
{ |
|||
get { return this.PlatformImpl.Bounds; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="RotateTransform.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
public class RotateTransform : Transform |
|||
{ |
|||
public static readonly PerspexProperty<double> AngleProperty = |
|||
PerspexProperty.Register<RotateTransform, double>("Angle"); |
|||
|
|||
public RotateTransform() |
|||
{ |
|||
} |
|||
|
|||
public RotateTransform(double angle) |
|||
{ |
|||
this.Angle = angle; |
|||
} |
|||
|
|||
public double Angle |
|||
{ |
|||
get { return this.GetValue(AngleProperty); } |
|||
set { this.SetValue(AngleProperty, value); } |
|||
} |
|||
|
|||
public override Matrix Value |
|||
{ |
|||
get { return Matrix.Rotation(Matrix.ToRadians(this.Angle)); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="StreamGeometry.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
using Perspex.Platform; |
|||
using Splat; |
|||
|
|||
public class StreamGeometry : Geometry |
|||
{ |
|||
public StreamGeometry() |
|||
{ |
|||
IPlatformRenderInterface factory = Locator.Current.GetService<IPlatformRenderInterface>(); |
|||
this.PlatformImpl = factory.CreateStreamGeometry(); |
|||
} |
|||
|
|||
public override Rect Bounds |
|||
{ |
|||
get { return this.PlatformImpl.Bounds; } |
|||
} |
|||
|
|||
public static StreamGeometry Parse(string s) |
|||
{ |
|||
StreamGeometry result = new StreamGeometry(); |
|||
|
|||
using (StreamGeometryContext ctx = result.Open()) |
|||
{ |
|||
PathMarkupParser parser = new PathMarkupParser(result, ctx); |
|||
parser.Parse(s); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
public StreamGeometryContext Open() |
|||
{ |
|||
return new StreamGeometryContext(((IStreamGeometryImpl)this.PlatformImpl).Open()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="StreamGeometryContext.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
using System; |
|||
using Perspex.Platform; |
|||
|
|||
public class StreamGeometryContext : IDisposable |
|||
{ |
|||
private IStreamGeometryContextImpl impl; |
|||
|
|||
public StreamGeometryContext(IStreamGeometryContextImpl impl) |
|||
{ |
|||
this.impl = impl; |
|||
} |
|||
|
|||
public void BeginFigure(Point startPoint, bool isFilled) |
|||
{ |
|||
this.impl.BeginFigure(startPoint, isFilled); |
|||
} |
|||
|
|||
public void LineTo(Point point) |
|||
{ |
|||
this.impl.LineTo(point); |
|||
} |
|||
|
|||
public void EndFigure(bool isClosed) |
|||
{ |
|||
this.impl.EndFigure(isClosed); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
this.impl.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Transform.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
public abstract class Transform : PerspexObject, ITransform |
|||
{ |
|||
public abstract Matrix Value { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="ButtonStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
|
|||
public class ButtonStyle : Styles |
|||
{ |
|||
public ButtonStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<Button>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<Button>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<Button>().Template().Id("border")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.BackgroundProperty, new SolidColorBrush(0xffdddddd)), |
|||
new Setter(Button.BorderBrushProperty, new SolidColorBrush(0xff707070)), |
|||
new Setter(Button.BorderThicknessProperty, 2.0), |
|||
new Setter(Button.ForegroundProperty, new SolidColorBrush(0xff000000)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<Button>().Class(":pointerover").Template().Id("border")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.BackgroundProperty, new SolidColorBrush(0xffbee6fd)), |
|||
new Setter(Button.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<Button>().Class(":pointerover").Class(":pressed").Template().Id("border")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.BackgroundProperty, new SolidColorBrush(0xffc4e5f6)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<Button>().Class(":pressed").Template().Id("border")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.BorderBrushProperty, new SolidColorBrush(0xffff628b)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(Button control) |
|||
{ |
|||
Border border = new Border |
|||
{ |
|||
Id = "border", |
|||
Padding = new Thickness(3), |
|||
Content = new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~Button.ContentProperty], |
|||
}, |
|||
[~Border.BackgroundProperty] = control[~Button.BackgroundProperty], |
|||
}; |
|||
|
|||
return border; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="CheckBoxStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System; |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Layout; |
|||
using Perspex.Media; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Styling; |
|||
|
|||
public class CheckBoxStyle : Styles |
|||
{ |
|||
public CheckBoxStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<CheckBox>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<CheckBox>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<CheckBox>().Template().Id("checkMark")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Shape.IsVisibleProperty, false), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<CheckBox>().Class(":checked").Template().Id("checkMark")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Shape.IsVisibleProperty, true), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(CheckBox control) |
|||
{ |
|||
Border result = new Border |
|||
{ |
|||
[~Border.BackgroundProperty] = control[~CheckBox.BackgroundProperty], |
|||
Content = new Grid |
|||
{ |
|||
ColumnDefinitions = new ColumnDefinitions |
|||
{ |
|||
new ColumnDefinition(GridLength.Auto), |
|||
new ColumnDefinition(new GridLength(1, GridUnitType.Star)), |
|||
}, |
|||
Children = new Controls |
|||
{ |
|||
new Border |
|||
{ |
|||
Id = "checkBorder", |
|||
BorderBrush = Brushes.Black, |
|||
BorderThickness = 2, |
|||
Width = 18, |
|||
Height = 18, |
|||
VerticalAlignment = VerticalAlignment.Center, |
|||
[Grid.ColumnProperty] = 0, |
|||
}, |
|||
new Rectangle |
|||
{ |
|||
Id = "checkMark", |
|||
Fill = Brushes.Black, |
|||
Width = 10, |
|||
Height = 10, |
|||
HorizontalAlignment = HorizontalAlignment.Center, |
|||
VerticalAlignment = VerticalAlignment.Center, |
|||
[Grid.ColumnProperty] = 0, |
|||
}, |
|||
new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~CheckBox.ContentProperty], |
|||
[Grid.ColumnProperty] = 1, |
|||
}, |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="ContentControlStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
|
|||
public class ContentControlStyle : Styles |
|||
{ |
|||
public ContentControlStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<ContentControl>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(ContentControl.TemplateProperty, ControlTemplate.Create<ContentControl>(this.Template)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(ContentControl control) |
|||
{ |
|||
return new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="DefaultTheme.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using Perspex.Styling; |
|||
|
|||
public class DefaultTheme : Styles |
|||
{ |
|||
public DefaultTheme() |
|||
{ |
|||
this.Add(new ButtonStyle()); |
|||
this.Add(new CheckBoxStyle()); |
|||
this.Add(new ContentControlStyle()); |
|||
this.Add(new ItemsControlStyle()); |
|||
this.Add(new TabControlStyle()); |
|||
this.Add(new TabItemStyle()); |
|||
this.Add(new TabStripStyle()); |
|||
this.Add(new TextBoxStyle()); |
|||
this.Add(new TreeViewStyle()); |
|||
this.Add(new TreeViewItemStyle()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="ItemsControlStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Styling; |
|||
|
|||
public class ItemsControlStyle : Styles |
|||
{ |
|||
public ItemsControlStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<ItemsControl>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<ItemsControl>(this.Template)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(ItemsControl control) |
|||
{ |
|||
return new ItemsPresenter |
|||
{ |
|||
[~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,106 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{3E10A5FA-E8DA-48B1-AD44-6A5B6CB7750F}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Themes.Default</RootNamespace> |
|||
<AssemblyName>Perspex.Themes.Default</AssemblyName> |
|||
<DefaultLanguage>en-US</DefaultLanguage> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<!-- A reference to the entire .NET Framework is automatically included --> |
|||
<ProjectReference Include="..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Controls\Perspex.Controls.csproj"> |
|||
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
|||
<Name>Perspex.Controls</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Interactivity\Perspex.Interactivity.csproj"> |
|||
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project> |
|||
<Name>Perspex.Interactivity</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="ButtonStyle.cs" /> |
|||
<Compile Include="CheckBoxStyle.cs" /> |
|||
<Compile Include="ContentControlStyle.cs" /> |
|||
<Compile Include="DefaultTheme.cs" /> |
|||
<Compile Include="ItemsControlStyle.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="TabControlStyle.cs" /> |
|||
<Compile Include="TabItemStyle.cs" /> |
|||
<Compile Include="TabStripStyle.cs" /> |
|||
<Compile Include="TextBoxStyle.cs" /> |
|||
<Compile Include="TreeViewItemStyle.cs" /> |
|||
<Compile Include="TreeViewStyle.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Splat"> |
|||
<HintPath>..\packages\Splat.1.3.3\lib\Portable-net45+win+wpa81+wp80\Splat.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Core"> |
|||
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Core.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Interfaces"> |
|||
<HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Interfaces.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Linq"> |
|||
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Linq.dll</HintPath> |
|||
</Reference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,30 @@ |
|||
using System.Resources; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Themes.Default")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Themes.Default")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
[assembly: NeutralResourcesLanguage("en")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,54 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TabControlStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Styling; |
|||
|
|||
public class TabControlStyle : Styles |
|||
{ |
|||
public TabControlStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TabControl>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TabControl.TemplateProperty, ControlTemplate.Create<TabControl>(this.Template)), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TabControl control) |
|||
{ |
|||
return new Grid |
|||
{ |
|||
RowDefinitions = new RowDefinitions |
|||
{ |
|||
new RowDefinition(GridLength.Auto), |
|||
new RowDefinition(new GridLength(1, GridUnitType.Star)), |
|||
}, |
|||
Children = new Controls |
|||
{ |
|||
new TabStrip |
|||
{ |
|||
[~TabStrip.ItemsProperty] = control[~TabControl.ItemsProperty], |
|||
}, |
|||
new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~TabControl.SelectedContentProperty], |
|||
[Grid.RowProperty] = 1, |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TabItemStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
|
|||
public class TabItemStyle : Styles |
|||
{ |
|||
public TabItemStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TabItem>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TextBox.FontSizeProperty, 28.7), |
|||
new Setter(Control.ForegroundProperty, Brushes.Gray), |
|||
new Setter(TabItem.TemplateProperty, ControlTemplate.Create<TabItem>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TabItem>().Class(":selected")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Control.ForegroundProperty, Brushes.Black), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TabItem control) |
|||
{ |
|||
return new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~TabItem.HeaderProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TabStripStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Styling; |
|||
|
|||
public class TabStripStyle : Styles |
|||
{ |
|||
public TabStripStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TabStrip>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TabStrip.TemplateProperty, ControlTemplate.Create<TabStrip>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TabStrip>().Template().OfType<StackPanel>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(StackPanel.GapProperty, 16.0), |
|||
new Setter(StackPanel.OrientationProperty, Orientation.Horizontal), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TabStrip control) |
|||
{ |
|||
return new ItemsPresenter |
|||
{ |
|||
[~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty], |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TextBoxStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System; |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Styling; |
|||
|
|||
public class TextBoxStyle : Styles |
|||
{ |
|||
public TextBoxStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TextBox>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TextBox.TemplateProperty, ControlTemplate.Create<TextBox>(this.Template)), |
|||
new Setter(TextBox.BorderBrushProperty, new SolidColorBrush(0xff707070)), |
|||
new Setter(TextBox.BorderThicknessProperty, 2.0), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TextBox>().Class(":focus").Template().Id("border")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TextBox.BorderBrushProperty, Brushes.Black), |
|||
}, |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TextBox control) |
|||
{ |
|||
Border result = new Border |
|||
{ |
|||
Id = "border", |
|||
Padding = new Thickness(2), |
|||
[~Border.BackgroundProperty] = control[~TextBox.BackgroundProperty], |
|||
[~Border.BorderBrushProperty] = control[~TextBox.BorderBrushProperty], |
|||
[~Border.BorderThicknessProperty] = control[~TextBox.BorderThicknessProperty], |
|||
Content = new Decorator |
|||
{ |
|||
Id = "textContainer", |
|||
} |
|||
}; |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,127 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeViewItemStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Layout; |
|||
using Perspex.Media; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Styling; |
|||
|
|||
public class TreeViewItemStyle : Styles |
|||
{ |
|||
public TreeViewItemStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TreeViewItem>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Button.TemplateProperty, ControlTemplate.Create<TreeViewItem>(this.Template)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TreeViewItem>().Template().Id("header")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(Border.PaddingProperty, new Thickness(2)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TreeViewItem>().Class(":selected").Template().Id("header")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TreeViewItem.BackgroundProperty, new SolidColorBrush(0xff086f9e)), |
|||
new Setter(TreeViewItem.ForegroundProperty, Brushes.White), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TreeViewItem>().Template().OfType<ToggleButton>().Class("expander")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(ToggleButton.TemplateProperty, ControlTemplate.Create<ToggleButton>(this.ToggleButtonTemplate)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TreeViewItem>().Template().OfType<ToggleButton>().Class("expander").Class(":checked").Template().OfType<Path>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(ToggleButton.RenderTransformProperty, new RotateTransform(90)), |
|||
}, |
|||
}, |
|||
new Style(x => x.OfType<TreeViewItem>().Class(":empty").Template().OfType<ToggleButton>().Class("expander")) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(ToggleButton.IsVisibleProperty, false), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TreeViewItem control) |
|||
{ |
|||
return new StackPanel |
|||
{ |
|||
Children = new Controls |
|||
{ |
|||
new Grid |
|||
{ |
|||
ColumnDefinitions = new ColumnDefinitions |
|||
{ |
|||
new ColumnDefinition(new GridLength(16, GridUnitType.Pixel)), |
|||
new ColumnDefinition(GridLength.Auto), |
|||
}, |
|||
Children = new Controls |
|||
{ |
|||
new ToggleButton |
|||
{ |
|||
Classes = new Classes("expander"), |
|||
[~~ToggleButton.IsCheckedProperty] = control[~TreeViewItem.IsExpandedProperty], |
|||
}, |
|||
new Border |
|||
{ |
|||
Id = "header", |
|||
[~ContentPresenter.BackgroundProperty] = control[~TreeViewItem.BackgroundProperty], |
|||
[Grid.ColumnProperty] = 1, |
|||
Content = new ContentPresenter |
|||
{ |
|||
[~ContentPresenter.ContentProperty] = control[~TreeViewItem.HeaderProperty], |
|||
}, |
|||
} |
|||
} |
|||
}, |
|||
new ItemsPresenter |
|||
{ |
|||
Margin = new Thickness(24, 0, 0, 0), |
|||
[~ItemsPresenter.ItemsProperty] = control[~TreeViewItem.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~TreeViewItem.ItemsPanelProperty], |
|||
[~ItemsPresenter.IsVisibleProperty] = control[~TreeViewItem.IsExpandedProperty], |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
|
|||
private Control ToggleButtonTemplate(ToggleButton control) |
|||
{ |
|||
return new Border |
|||
{ |
|||
Content = new Path |
|||
{ |
|||
Fill = Brushes.Black, |
|||
Stroke = Brushes.Black, |
|||
StrokeThickness = 1, |
|||
HorizontalAlignment = HorizontalAlignment.Center, |
|||
VerticalAlignment = VerticalAlignment.Center, |
|||
Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"), |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TreeViewStyle.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
|
|||
public class TreeViewStyle : Styles |
|||
{ |
|||
public TreeViewStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<TreeView>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(TreeView.TemplateProperty, ControlTemplate.Create<TreeView>(this.Template)), |
|||
new Setter(TreeView.BorderBrushProperty, Brushes.Black), |
|||
new Setter(TreeView.BorderThicknessProperty, 1.0), |
|||
}, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
private Control Template(TreeView control) |
|||
{ |
|||
return new Border |
|||
{ |
|||
Padding = new Thickness(4), |
|||
[~Border.BackgroundProperty] = control[~TreeView.BackgroundProperty], |
|||
[~Border.BorderBrushProperty] = control[~TreeView.BorderBrushProperty], |
|||
[~Border.BorderThicknessProperty] = control[~TreeView.BorderThicknessProperty], |
|||
Content = new ItemsPresenter |
|||
{ |
|||
[~ItemsPresenter.ItemsProperty] = control[~TreeView.ItemsProperty], |
|||
[~ItemsPresenter.ItemsPanelProperty] = control[~TreeView.ItemsPanelProperty], |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Rx-Core" version="2.1.30214.0" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-Interfaces" version="2.1.30214.0" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-Main" version="2.1.30214.0" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="portable-net45+win" /> |
|||
<package id="Splat" version="1.3.3" targetFramework="portable-net45+win" /> |
|||
</packages> |
|||
Loading…
Reference in new issue