Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:00:12+00:00 2026-05-26T21:00:12+00:00

I’ve got a requirement to create several shapes based on a supplied size (all

  • 0

I’ve got a requirement to create several shapes based on a supplied size (all of them have the same height/width) and have their sizes be databound to that supplied property on the datacontext.

Most of the shapes are easy: Circle (ellipse with height/width bound), square (rectangle with height/width bound), diamond (same as square, then use a RotateTransform), + (two lines), X (two lines).

But I’m trying to figure out how to do it for a triangle and I can’t figure it out. It needs to be a filled object, so I can’t just do it with three lines.

But all of the ways i’ve seen to do it (w/ a Path or a Polygon) end up taking Point objects (StartPoint, EndPoint, etc). And you can’t bind to the X or Y values of the Point object.

Am I missing something? Or do I need to write my own custom shape or something?

Edit: To add a little bit of clarity… the type of triangle I’m creating doesn’t really matter. It can be equilateral or isosceles. I was targeting an isosceles, so that it would have a base with the databound width and the top “tip” of the triangle will be at the mid-point of the databound width and at Y=0. That was just an optimization for simplicity’s sake

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:00:12+00:00Added an answer on May 26, 2026 at 9:00 pm

    The behavior class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Shapes;
    using System.Windows.Media;
    
    namespace WpfApplication1
    {
        public enum ShapeType
        {
            Rectangle,
            Isosceles,
            Ellipse,
            Dice,
            Hexagon
        }
    
        public class PathControl
        {
            public static readonly DependencyProperty ShapeTypeProperty =
                DependencyProperty.RegisterAttached("ShapeType",
                typeof(ShapeType?),
                typeof(DependencyObject),
                new PropertyMetadata(null, 
                    new PropertyChangedCallback((sender, args) => 
                    { 
                        Path path = sender as Path;
                        ShapeType? shapeType = (ShapeType?)args.NewValue;
    
                        //todo: use a WeakEvent
                        path.SizeChanged += 
                            (pathSender, pathArgs) => 
                            {
                                PathControl.InvalidatePath((Path)sender, shapeType);
                            };
    
                    })));
    
    
            private static void InvalidatePath(Path path, ShapeType? shapeType)
            {
                if (path != null
                    && shapeType.HasValue)
                {
                    string source = null;
    
                    double netWidth = path.Width - 2 * path.StrokeThickness,
                           netHeight = path.Height - 2 * path.StrokeThickness;
    
                    if (shapeType == ShapeType.Rectangle)
                    {
                        source = string.Format("M0,0 h{0} v{1} h-{0} z",
                            new object[2]
                            {
                                netWidth,
                                netHeight
                            });
                    }
                    else if (shapeType == ShapeType.Isosceles)
                    {
                        source = string.Format("M0,{1} l{0},-{1} {0},{1} z",
                            new object[2]
                            {
                                netWidth / 2,
                                netHeight
                            });
                    }
                    else
                    {
                        throw new NotImplementedException(shapeType.ToString());
                    }
    
                    path.Data = Geometry.Parse(source);
                }
            }
    
            public static void SetShapeType(DependencyObject o, ShapeType e)
            {
                o.SetValue(PathControl.ShapeTypeProperty, e);
            }
    
            public static ShapeType? GetShapeType(DependencyObject o)
            {
                return (ShapeType)o.GetValue(PathControl.ShapeTypeProperty);
            }
        }
    }
    

    The XAML:

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525"
            xmlns:local="clr-namespace:WpfApplication1">
        <Grid>
            <Path Width="100" Height="100" Stroke="Green" StrokeThickness="2" Fill="Yellow"
                  local:PathControl.ShapeType="Isosceles">
                <Path.RenderTransform>
                    <RotateTransform Angle="90"></RotateTransform>
                </Path.RenderTransform>
            </Path>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.