Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After experimenting with this for a while, I've come up with a solution that satisfies my needs. I'll post it here for posterity. Hopefully it saves someone else the 6 hours or so I've spent on this issue.</p> <p>Couple classes I use that are defined elsewhere:</p> <ul> <li><strong>PlanarElement</strong>: Simply describes a 2d "thing" with a Boundary property exposing a Polygon and an Openings property exposing an IEnumerable list of Polygon objects</li> <li><strong>Polygon</strong>: 2d planar geometric class exposing a property of type IEnumerable of type Point</li> <li><strong>Point</strong>: 3d geometric point</li> </ul> <hr> <p>Here is the solution:</p> <p>1) Here is the ItemsControl to which my PlanarMembers will be bound</p> <pre><code>&lt;ItemsControl&gt; &lt;ItemsControl.Resources&gt; &lt;DataTemplate DataType="{x:Type o:PlanarMember}"&gt; &lt;Path Stroke="Black" StrokeThickness="1" Data="{Binding Converter={StaticResource PlanarMemberConverter}}"&gt; &lt;Path.Fill&gt; &lt;SolidColorBrush Opacity="0.5" Color="LightGray" /&gt; &lt;/Path.Fill&gt; &lt;/Path&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.Resources&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;Canvas RenderTransform="{StaticResource CurrentDisplayTransform}"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;/ItemsControl&gt; </code></pre> <p>2) Notice the use of PlanarMemberConverter in the Path's Data setting, created here:</p> <pre><code>&lt;this:PlanarMemberConverter x:Key="PlanarMemberConverter" /&gt; </code></pre> <p>3) The actual IValueConverter derived class is defined here:</p> <pre><code>[ValueConversion(typeof(PlanarMember), typeof(Geometry))] class PlanarMemberConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (targetType != typeof(Geometry)) return null; var planarMember = value as PlanarMember; var collection = new PathFigureCollection(planarMember.Openings.Count() + 1) { new PathFigure( planarMember.Boundary.Vertices.First().AsPoint(), ToSegments(planarMember.Boundary.Vertices), true){IsFilled = true} }; foreach (var opening in planarMember.Openings) { collection.Add(new PathFigure( opening.Vertices.First().AsPoint(), ToSegments(opening.Vertices), true) { IsFilled = true }); } return new PathGeometry(collection) {FillRule = FillRule.EvenOdd}; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion public IEnumerable&lt;PathSegment&gt; ToSegments(IEnumerable&lt;Point&gt; points) { return from point in points select (PathSegment)new LineSegment(point.AsPoint(), true); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload