-
-
Save JCBurnside/11e5269f75a7fce70ab7f1ff46b3f3fa to your computer and use it in GitHub Desktop.
What am I doing wrong now?
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
Portable.Xaml.XamlObjectWriterException: Type '{clr-namespace:Avalonia.Controls;assembly=Avalonia.Controls}ITemplate({clr-namespace:Avalonia.Controls;assembly=Avalonia.Controls}IPanel)' does not have a content property. | |
at Portable.Xaml.XamlObjectWriterInternal.OnWriteStartMember(XamlMember property) | |
at Portable.Xaml.XamlWriterInternalBase.WriteStartMember(XamlMember property) | |
at Portable.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property) | |
at Avalonia.Markup.Xaml.PortableXaml.AvaloniaXamlObjectWriter.WriteStartMember(XamlMember property) | |
at Portable.Xaml.XamlWriter.WriteNode(XamlReader reader) | |
at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter) | |
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.LoadFromReader(XamlReader reader, AvaloniaXamlContext context, IAmbientProvider parentAmbientProvider) | |
at Avalonia.DesignerSupport.DesignWindowLoader.LoadDesignerWindow(String xaml, String assemblyPath) | |
at Avalonia.DesignerSupport.Remote.RemoteDesignerEntryPoint.<>c__DisplayClass18_0.<OnTransportMessage>b__0() | |
Sending StartDesignerSessionMessage |
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
<UserControl xmlns="https://github.com/avaloniaui" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
x:Class="CanvasTesting.Views.Star"> | |
<ItemsControl Items="{Binding Lines}"> | |
<ItemsControl.ItemsPanel> | |
<Canvas Background="{Binding Background}"/> | |
</ItemsControl.ItemsPanel> | |
<ItemsControl.DataTemplates> | |
<Line Start="{Binding Start}" End="{Binding End}"/> | |
</ItemsControl.DataTemplates> | |
</ItemsControl> | |
</UserControl> |
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
using Avalonia; | |
using Avalonia.Controls; | |
using Avalonia.Markup.Xaml; | |
using Avalonia.Media; | |
using CanvasTesting.ViewModels; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using static System.Math; | |
namespace CanvasTesting.Views | |
{ | |
public class Star : UserControl | |
{ | |
public Star() | |
{ | |
this.InitializeComponent(); | |
} | |
public static readonly DirectProperty<Star, uint> PointsProperty = AvaloniaProperty.RegisterDirect<Star, uint>( | |
nameof(Points), | |
o => o.Points, | |
(o, v) => o.Points = v, unsetValue: 3); | |
private uint points = 3; | |
public uint Points | |
{ | |
get => points; | |
set | |
{ | |
if (value < 3) throw new ArgumentOutOfRangeException(nameof(value), value, "Points Cannot be less than 3. Actual {0}."); | |
if (points != value) | |
{ | |
IEnumerable<LinePointsViewModel> old = Lines; | |
SetAndRaise(PointsProperty, ref points, value); | |
this.RaisePropertyChanged(LinesProperty, old, Lines); | |
} | |
} | |
} | |
public static readonly DirectProperty<Star, DrawModes> DrawModeProperty = AvaloniaProperty.RegisterDirect<Star, DrawModes>(nameof(DrawMode), | |
o => o.DrawMode, | |
(o, v) => o.DrawMode = v, | |
unsetValue: DrawModes.Any); | |
private DrawModes drawMode; | |
public DrawModes DrawMode | |
{ | |
get => drawMode; | |
set | |
{ | |
if (drawMode != value) | |
{ | |
IEnumerable<LinePointsViewModel> old = Lines; | |
this.SetAndRaise(DrawModeProperty, ref drawMode, value); | |
this.RaisePropertyChanged(LinesProperty, old, Lines); | |
} | |
} | |
} | |
public static readonly DirectProperty<Star, uint> RadiusProperty = AvaloniaProperty.RegisterDirect<Star, uint>(nameof(Radius), | |
o => o.Radius, | |
(o, v) => o.Radius = v, | |
unsetValue: 1); | |
private uint radius; | |
public uint Radius | |
{ | |
get => radius; | |
set | |
{ | |
if (radius != value) | |
{ | |
IEnumerable<LinePointsViewModel> old = Lines; | |
this.SetAndRaise(RadiusProperty, ref radius, value); | |
this.RaisePropertyChanged(LinesProperty, old, Lines); | |
} | |
} | |
} | |
public static readonly DirectProperty<Star, IEnumerable<LinePointsViewModel>> LinesProperty = AvaloniaProperty.RegisterDirect<Star, IEnumerable<LinePointsViewModel>>(nameof(Lines), | |
o => o.Lines); | |
public List<LinePointsViewModel> Lines | |
{ | |
get | |
{ | |
List<LinePointsViewModel> list = new List<LinePointsViewModel>(); | |
var listPoints = Enumerable.Range(0, (int)points).Select(i => new Point(GenX(i), GenY(i))).ToList(); | |
if (points % 4 == 0 && drawMode.HasFlag(DrawModes.Square)) | |
{ | |
foreach (int i in Enumerable.Range(0, (int)points)) | |
{ | |
list.Add(new LinePointsViewModel | |
{ | |
Start = listPoints[i], | |
End = listPoints[(i + (int)points / 4) % (int)points] | |
}); | |
} | |
} | |
else if (points % 3 == 0 && drawMode.HasFlag(DrawModes.Triangle)) | |
{ | |
foreach (int i in Enumerable.Range(0, (int)points)) | |
{ | |
list.Add(new LinePointsViewModel | |
{ | |
Start = listPoints[i], | |
End = listPoints[(int)(i + points / 3) % (int)points] | |
}); | |
} | |
} | |
else if (points % 2 == 0 && drawMode.HasFlag(DrawModes.PassTwo)) | |
{ | |
foreach (int i in Enumerable.Range(0, (int)points)) | |
{ | |
list.Add(new LinePointsViewModel | |
{ | |
Start = listPoints[i], | |
End = listPoints[(i + 3) % (int)points] | |
}); | |
} | |
} | |
else if (drawMode.HasFlag(DrawModes.Oppisite)) | |
{ | |
foreach (int i in Enumerable.Range(0, (int)points)) | |
{ | |
list.Add(new LinePointsViewModel | |
{ | |
Start = listPoints[i], | |
End = listPoints[(i + (int)points / 2) % (int)points] | |
}); | |
} | |
} | |
else if (drawMode.HasFlag(DrawModes.PassTwo)) | |
{ | |
foreach (int i in Enumerable.Range(0, (int)points)) | |
{ | |
list.Add(new LinePointsViewModel | |
{ | |
Start = listPoints[i], | |
End = listPoints[(i + 3) % (int)points] | |
}); | |
} | |
} | |
else if (drawMode.HasFlag(DrawModes.PassOne)) | |
{ | |
foreach (int i in Enumerable.Range(0, (int)points)) | |
{ | |
list.Add(new LinePointsViewModel | |
{ | |
Start = listPoints[i], | |
End = listPoints[(i + 2) % (int)points] | |
}); | |
} | |
} | |
return list; | |
} | |
} | |
private double GenX(int ctr) => radius * Cos(2 * PI * ctr / points) + Bounds.Center.X; | |
private double GenY(int ctr) => radius * Sin(2 * PI * ctr / points) + Bounds.Center.Y; | |
private void InitializeComponent() | |
{ | |
AvaloniaXamlLoader.Load(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment