Browse Source

Added Shape and Path

Draw checkbox check using Path. Still very hacky - measurement is off.
pull/4/head
Steven Kirk 12 years ago
parent
commit
041b276cc1
  1. 3
      Perspex.Direct2D1/Direct2D1Platform.cs
  2. 21
      Perspex.Direct2D1/Media/DrawingContext.cs
  3. 27
      Perspex.Direct2D1/Media/GeometryImpl.cs
  4. 44
      Perspex.Direct2D1/Media/StreamGeometryContextImpl.cs
  5. 35
      Perspex.Direct2D1/Media/StreamGeometryImpl.cs
  6. 6
      Perspex.Direct2D1/Perspex.Direct2D1.csproj
  7. 28
      Perspex.Direct2D1/PrimitiveExtensions.cs
  8. 6
      Perspex.Direct2D1/Renderer.cs
  9. 26
      Perspex.Windows/Media/Direct2DStreamGeometry.cs
  10. 3
      Perspex.Windows/Perspex.Windows.csproj
  11. 18
      Perspex/Media/Geometry.cs
  12. 13
      Perspex/Media/IGeometryImpl.cs
  13. 10
      Perspex/Media/IStreamGeometryContextImpl.cs
  14. 3
      Perspex/Media/IStreamGeometryImpl.cs
  15. 291
      Perspex/Media/PathMarkupParser.cs
  16. 23
      Perspex/Media/StreamGeometry.cs
  17. 23
      Perspex/Media/StreamGeometryContext.cs
  18. 16
      Perspex/Media/Stretch.cs
  19. 3
      Perspex/Perspex.csproj
  20. 11
      Perspex/Shapes/Path.cs
  21. 95
      Perspex/Shapes/Shape.cs
  22. 16
      Perspex/Themes/Default/CheckBoxStyle.cs
  23. 18
      TestApplication/Program.cs

3
Perspex.Direct2D1/Direct2D1Platform.cs

@ -6,6 +6,7 @@
namespace Perspex.Direct2D1
{
using Perspex.Direct2D1.Media;
using Perspex.Media;
using Perspex.Platform;
using Splat;
@ -22,7 +23,9 @@ namespace Perspex.Direct2D1
locator.Register(() => d2d1Factory, typeof(SharpDX.Direct2D1.Factory));
locator.Register(() => dwFactory, typeof(SharpDX.DirectWrite.Factory));
locator.Register(() => textService, typeof(ITextService));
locator.Register(() => new Renderer(), typeof(IRenderer));
locator.Register(() => new StreamGeometryImpl(), typeof(IStreamGeometryImpl));
}
}
}

21
Perspex.Direct2D1/DrawingContext.cs → Perspex.Direct2D1/Media/DrawingContext.cs

@ -4,10 +4,11 @@
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1
namespace Perspex.Direct2D1.Media
{
using System;
using System.Reactive.Disposables;
using Perspex.Direct2D1.Media;
using Perspex.Media;
using SharpDX;
using SharpDX.Direct2D1;
@ -58,7 +59,23 @@ namespace Perspex.Direct2D1
/// <param name="geometry">The geometry.</param>
public void DrawGeometry(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry)
{
// TODO
if (brush != null)
{
using (SharpDX.Direct2D1.SolidColorBrush d2dBrush = this.Convert(brush))
{
GeometryImpl impl = (GeometryImpl)geometry.PlatformImpl;
this.renderTarget.FillGeometry(impl.Geometry, d2dBrush);
}
}
if (pen != null)
{
using (SharpDX.Direct2D1.SolidColorBrush d2dBrush = this.Convert(pen.Brush))
{
GeometryImpl impl = (GeometryImpl)geometry.PlatformImpl;
this.renderTarget.DrawGeometry(impl.Geometry, d2dBrush, (float)pen.Thickness);
}
}
}
/// <summary>

27
Perspex.Direct2D1/Media/GeometryImpl.cs

@ -0,0 +1,27 @@
// -----------------------------------------------------------------------
// <copyright file="GeometryImpl.cs" company="Tricycle">
// Copyright 2014 Tricycle. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using System;
using Perspex.Media;
using SharpDX.Direct2D1;
using Splat;
public abstract class GeometryImpl : IGeometryImpl
{
public abstract Rect Bounds
{
get;
}
public SharpDX.Direct2D1.Geometry Geometry
{
get;
protected set;
}
}
}

44
Perspex.Direct2D1/Media/StreamGeometryContextImpl.cs

@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="Direct2D1StreamGeometryContext.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using System;
using Perspex.Media;
using SharpDX.Direct2D1;
using Splat;
public class StreamGeometryContextImpl : IStreamGeometryContextImpl
{
private GeometrySink sink;
public StreamGeometryContextImpl(GeometrySink sink)
{
this.sink = sink;
}
public void BeginFigure(Point startPoint, bool isFilled)
{
this.sink.BeginFigure(startPoint.ToSharpDX(), isFilled ? FigureBegin.Filled : FigureBegin.Hollow);
}
public void LineTo(Point point)
{
this.sink.AddLine(point.ToSharpDX());
}
public void EndFigure(bool isClosed)
{
this.sink.EndFigure(isClosed ? FigureEnd.Closed : FigureEnd.Open);
}
public void Dispose()
{
this.sink.Close();
this.sink.Dispose();
}
}
}

35
Perspex.Direct2D1/Media/StreamGeometryImpl.cs

@ -0,0 +1,35 @@
// -----------------------------------------------------------------------
// <copyright file="Direct2DStreamGeometry.cs" company="Tricycle">
// Copyright 2014 Tricycle. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using System;
using Perspex.Media;
using SharpDX.Direct2D1;
using Splat;
public class StreamGeometryImpl : GeometryImpl, IStreamGeometryImpl
{
private PathGeometry geometry;
public StreamGeometryImpl()
{
Factory factory = Locator.Current.GetService<Factory>();
this.geometry = new PathGeometry(factory);
this.Geometry = this.geometry;
}
public override Rect Bounds
{
get { return geometry.GetBounds().ToPerspex(); }
}
public IStreamGeometryContextImpl Open()
{
return new StreamGeometryContextImpl(geometry.Open());
}
}
}

6
Perspex.Direct2D1/Perspex.Direct2D1.csproj

@ -63,7 +63,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Direct2D1Platform.cs" />
<Compile Include="DrawingContext.cs" />
<Compile Include="Media\DrawingContext.cs" />
<Compile Include="Media\StreamGeometryContextImpl.cs" />
<Compile Include="Media\GeometryImpl.cs" />
<Compile Include="Media\StreamGeometryImpl.cs" />
<Compile Include="PrimitiveExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="TextService.cs" />

28
Perspex.Direct2D1/PrimitiveExtensions.cs

@ -0,0 +1,28 @@
// -----------------------------------------------------------------------
// <copyright file="PrimitiveExtensions.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharpDX;
public static class PrimitiveExtensions
{
public static Rect ToPerspex(this RectangleF r)
{
return new Rect(r.X, r.Y, r.Width, r.Height);
}
public static Vector2 ToSharpDX(this Perspex.Point p)
{
return new Vector2((float)p.X, (float)p.Y);
}
}
}

6
Perspex.Direct2D1/Renderer.cs

@ -7,9 +7,11 @@
namespace Perspex.Direct2D1
{
using System;
using Perspex.Direct2D1.Media;
using Perspex.Platform;
using SharpDX;
using SharpDX.Direct2D1;
using Splat;
using DwFactory = SharpDX.DirectWrite.Factory;
using Matrix = Perspex.Media.Matrix;
@ -36,8 +38,8 @@ namespace Perspex.Direct2D1
throw new InvalidOperationException("Cannot initialize Renderer more than once.");
}
this.Direct2DFactory = new Factory();
this.DirectWriteFactory = new DwFactory();
this.Direct2DFactory = Locator.Current.GetService<Factory>();
this.DirectWriteFactory = Locator.Current.GetService<DwFactory>();
RenderTargetProperties renderTargetProperties = new RenderTargetProperties
{

26
Perspex.Windows/Media/Direct2DStreamGeometry.cs

@ -1,26 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="Direct2DStreamGeometry.cs" company="Tricycle">
// Copyright 2014 Tricycle. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Windows.Media
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Perspex.Media;
using SharpDX.Direct2D1;
public class Direct2DStreamGeometry : IStreamGeometryImpl
{
private PathGeometry geometry;
public void Initalize(IStreamGeometryImpl impl)
{
//this.geometry = new PathGeometry();
}
}
}

3
Perspex.Windows/Perspex.Windows.csproj

@ -57,9 +57,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Input\MouseDevice.cs" />
<Compile Include="Media\Direct2DStreamGeometry.cs" />
<Compile Include="Media\TextService.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="Threading\Dispatcher.cs" />
<Compile Include="Threading\DispatcherFrame.cs" />
<Compile Include="Threading\DispatcherOperation.cs" />

18
Perspex/Media/Geometry.cs

@ -6,13 +6,17 @@
namespace Perspex.Media
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Geometry
public abstract class Geometry
{
public abstract Rect Bounds
{
get;
}
public IGeometryImpl PlatformImpl
{
get;
protected set;
}
}
}

13
Perspex/Media/IGeometryImpl.cs

@ -0,0 +1,13 @@
// -----------------------------------------------------------------------
// <copyright file="IGeometryImpl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Media
{
public interface IGeometryImpl
{
Rect Bounds { get; }
}
}

10
Perspex/Media/IStreamGeometryContextImpl.cs

@ -6,8 +6,14 @@
namespace Perspex.Media
{
public interface IStreamGeometryContextImpl
using System;
public interface IStreamGeometryContextImpl : IDisposable
{
void Initialize(IStreamGeometryImpl streamGeometry);
void BeginFigure(Point startPoint, bool isFilled);
void LineTo(Point point);
void EndFigure(bool isClosed);
}
}

3
Perspex/Media/IStreamGeometryImpl.cs

@ -6,7 +6,8 @@
namespace Perspex.Media
{
public interface IStreamGeometryImpl
public interface IStreamGeometryImpl : IGeometryImpl
{
IStreamGeometryContextImpl Open();
}
}

291
Perspex/Media/PathMarkupParser.cs

@ -0,0 +1,291 @@
// -----------------------------------------------------------------------
// <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 startPoint = new Point();
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:
point = startPoint = 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(true);
}
}
}
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;
bool canMove = lastCommand == Command.None || lastCommand == Command.FillRule || lastCommand == Command.Close;
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 + "'.");
}
}
if (!canMove && command <= Command.MoveRelative)
{
command += 2;
}
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;
}
}
}
}
}

23
Perspex/Media/StreamGeometry.cs

@ -13,18 +13,29 @@ namespace Perspex.Media
{
public StreamGeometry()
{
this.Impl = Locator.Current.GetService<IStreamGeometryImpl>();
this.PlatformImpl = Locator.Current.GetService<IStreamGeometryImpl>();
}
public StreamGeometryContext Open()
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 override Rect Bounds
{
return new StreamGeometryContext(this);
get { return this.PlatformImpl.Bounds; }
}
internal IStreamGeometryImpl Impl
public StreamGeometryContext Open()
{
get;
private set;
return new StreamGeometryContext(((IStreamGeometryImpl)this.PlatformImpl).Open());
}
}
}

23
Perspex/Media/StreamGeometryContext.cs

@ -9,22 +9,33 @@ namespace Perspex.Media
using System;
using Splat;
public class StreamGeometryContext : Geometry
public class StreamGeometryContext : IDisposable
{
private IStreamGeometryContextImpl impl;
public StreamGeometryContext(StreamGeometry geometry)
public StreamGeometryContext(IStreamGeometryContextImpl impl)
{
this.impl = Locator.Current.GetService<IStreamGeometryContextImpl>();
this.impl.Initialize(geometry.Impl);
this.impl = impl;
}
public void BeginFigure(Point startPoint, bool isFilled, bool isClosed)
public void BeginFigure(Point startPoint, bool isFilled)
{
this.impl.BeginFigure(startPoint, isFilled);
}
public void LineTo(Point point, bool isStroked, bool isSmoothJoin)
public void LineTo(Point point)
{
this.impl.LineTo(point);
}
public void EndFigure(bool isClosed)
{
this.impl.EndFigure(isClosed);
}
public void Dispose()
{
this.impl.Dispose();
}
}
}

16
Perspex/Media/Stretch.cs

@ -0,0 +1,16 @@
// -----------------------------------------------------------------------
// <copyright file="Stretch.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Media
{
public enum Stretch
{
None,
Fill,
Uniform,
UniformToFill,
}
}

3
Perspex/Perspex.csproj

@ -83,10 +83,13 @@
<Compile Include="Input\Raw\RawInputEventArgs.cs" />
<Compile Include="Input\Raw\RawMouseEventArgs.cs" />
<Compile Include="Media\IStreamGeometryContextImpl.cs" />
<Compile Include="Media\IGeometryImpl.cs" />
<Compile Include="Media\IStreamGeometryImpl.cs" />
<Compile Include="Media\PathMarkupParser.cs" />
<Compile Include="Media\StreamGeometryContext.cs" />
<Compile Include="Media\StreamGeometry.cs" />
<Compile Include="Media\Geometry.cs" />
<Compile Include="Media\Stretch.cs" />
<Compile Include="Shapes\Path.cs" />
<Compile Include="Shapes\Shape.cs" />
<Compile Include="Platform\IRenderer.cs" />

11
Perspex/Shapes/Path.cs

@ -6,6 +6,7 @@
namespace Perspex.Shapes
{
using System;
using Perspex.Media;
public class Path : Shape
@ -19,9 +20,17 @@ namespace Perspex.Shapes
set { this.SetValue(DataProperty, value); }
}
public override Geometry DefiningGeometry
{
get { return this.Data; }
}
public override void Render(IDrawingContext context)
{
context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.Data);
if (this.Data != null && this.Visibility == Visibility.Visible)
{
context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.Data);
}
}
}
}

95
Perspex/Shapes/Shape.cs

@ -6,26 +6,46 @@
namespace Perspex.Shapes
{
using System;
using Perspex.Controls;
using Perspex.Media;
public class Shape : Control
public abstract class Shape : Control
{
public PerspexProperty<Brush> FillProperty =
PerspexProperty.Register<Shape, Brush>("Fill");
public PerspexProperty<Stretch> StretchProperty =
PerspexProperty.Register<Shape, Stretch>("Stretch");
public PerspexProperty<Brush> StrokeProperty =
PerspexProperty.Register<Shape, Brush>("Stroke");
public 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); }
@ -37,5 +57,78 @@ namespace Perspex.Shapes
get { return this.GetValue(StrokeThicknessProperty); }
set { this.SetValue(StrokeThicknessProperty, value); }
}
protected override Size MeasureContent(Size availableSize)
{
Pen pen = (this.Stroke != null) ? new Pen(this.Stroke, this.StrokeThickness) : null;
Rect shapeBounds = this.RenderedGeometry.Bounds;
double desiredX = availableSize.Width;
double desiredY = availableSize.Height;
double sx = 0.0;
double sy = 0.0;
if (this.Stretch == Stretch.None)
{
return new Size(
shapeBounds.X + shapeBounds.Width,
shapeBounds.Y + shapeBounds.Height);
}
if (double.IsInfinity(availableSize.Width))
{
desiredX = shapeBounds.Width;
}
if (double.IsInfinity(availableSize.Height))
{
desiredY = shapeBounds.Height;
}
if (shapeBounds.Width > 0)
{
sx = desiredX / shapeBounds.Width;
}
if (shapeBounds.Height > 0)
{
sy = desiredY / shapeBounds.Height;
}
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:
break;
}
return new Size(shapeBounds.Width * sx, shapeBounds.Height * sy);
}
}
}

16
Perspex/Themes/Default/CheckBoxStyle.cs

@ -6,9 +6,11 @@
namespace Perspex.Themes.Default
{
using System;
using System.Linq;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Shapes;
using Perspex.Styling;
public class CheckBoxStyle : Styles
@ -53,14 +55,16 @@ namespace Perspex.Themes.Default
{
new Border
{
BorderThickness = 2.0,
BorderBrush = new SolidColorBrush(0xff000000),
Padding = new Thickness(2),
Content = new TextBlock
BorderThickness = 2,
BorderBrush = new SolidColorBrush(Color.FromUInt32(0xff000000)),
Padding = new Thickness(8),
Content = new Path
{
Id = "checkMark",
Text = "Y",
Background = null,
Data = StreamGeometry.Parse("M0,0 L10,10 Z M10,0 L0,10"),
Stroke = new SolidColorBrush(Color.FromUInt32(0xff000000)),
StrokeThickness = 2,
VerticalAlignment = VerticalAlignment.Center,
},
},
new ContentPresenter

18
TestApplication/Program.cs

@ -51,15 +51,15 @@ namespace TestApplication
Gap = 6,
Children = new PerspexList<Control>
{
new Button
{
Content = "Button",
},
new Button
{
Content = "Explict Background",
Background = new SolidColorBrush(0xffa0a0ff),
},
//new Button
//{
// Content = "Button",
//},
//new Button
//{
// Content = "Explict Background",
// Background = new SolidColorBrush(0xffa0a0ff),
//},
new CheckBox
{
Content = "Checkbox",

Loading…
Cancel
Save