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 8197183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:41:23+00:00 2026-06-07T05:41:23+00:00

SOLUTION Dynamic Margin on Window Drag So I’m trying to get my polygon to

  • 0

SOLUTION
Dynamic Margin on Window Drag

So I’m trying to get my polygon to move as the window is moved. I have;

    private void ResetPolygon(Point Point1, Point Point2, Point Point3)
    {
        SpeechPoly.Points.Clear();
        ObservableCollection<Point> myPointCollection = new ObservableCollection<Point>();
        myPointCollection.Add(Point3);
        myPointCollection.Add(Point2);
        myPointCollection.Add(Point1);
        foreach (Point p in myPointCollection)
        {
            SpeechPoly.Points.Add(p);
        }
    }

    private void Window_LocationChanged(object sender, EventArgs e)
    {
        if (this.IsLoaded)
        {
            Point Point1 = new Point(newPoint3);
            Point Point2 = new Point(newPoint2);
            Point Point3 = new Point(newPoint1);
            ResetPolygon(newPoint1, newPoint2, newPoint3);

//Write out the values of both the list and the polygon to screen!
            txtBlock.Text = newPoint1.X.ToString("N2") + ", " + newPoint1.Y.ToString("N2") + 
"\n" + newPoint2.X.ToString("N2") + ", " + newPoint2.Y.ToString("N2") + "\n" + 
newPoint3.X.ToString("N2") + ", " + newPoint3.Y.ToString("N2");

            txtBlock.Text += "\n" + SpeechPoly.Points[0].X.ToString("N2") + ", " + 
SpeechPoly.Points[0].Y.ToString("N2") + "\n" + SpeechPoly.Points[1].X.ToString("N2") + ", " +        
SpeechPoly.Points[1].Y.ToString("N2") + "\n" + SpeechPoly.Points[2].X.ToString("N2") + ", "+ 
SpeechPoly.Points[2].Y.ToString("N2");
                        }
                    }

But the Polygon remains the same shape no matter what, even though the Textblock clearly shows the values of all the Points in the List and the Polygon‘s points are definitely changing.

I’ve also tried to bind the Points property of the Polygon to my code.

<Polygon
    Name="SpeechPoly"
    Points="{Binding myPointCollection, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
    Stroke="Black" 
    StrokeThickness="2"
    </Polygon>

I’ve also tried using a pointsCollection as opposed List<Points> but same result. Almost seems like the Polygon is not refreshing.

  • 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-06-07T05:41:24+00:00Added an answer on June 7, 2026 at 5:41 am

    I was not being satisfied with the previous answer I gave as it is after all a workaround..

    I found a better solution to the problem which will not require to reset the databinds.

    So the binding from XAML is being directed to a property with INCC however the data itself is converted to Points for the polygon to use when drawing.

    <Window x:Class="WpfApplication9.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication9"
        Title="MainWindow" Height="350" Width="525" LocationChanged="Window_LocationChanged" >
    <Window.Resources>
        <local:MyPointCollectionConverter x:Key="mcolconv" />
    </Window.Resources>
    <Canvas>
        <Polygon Name="SpeechPoly" Stroke="Black" StrokeThickness="2" 
                 Points="{Binding Path=myPointCollection, Converter={StaticResource mcolconv}}" />
    </Canvas>
    

    using System;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Media;
    
    namespace WpfApplication9
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        private ObservableCollection<Point> _myPointCollection = new ObservableCollection<Point>();
        public ObservableCollection<Point> myPointCollection { get { return _myPointCollection; } }
    
        public MainWindow()
        {
            myPointCollection.Add(new Point(100, 50));
            myPointCollection.Add(new Point(150, 100));
            myPointCollection.Add(new Point(50, 100));
            InitializeComponent();
            DataContext = this;
        }
    
        private void ResetPolygon(Point Point1, Point Point2, Point Point3)
        {
            myPointCollection.Clear();
            myPointCollection.Add(Point1);
            myPointCollection.Add(Point2);
            myPointCollection.Add(Point3);
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("myPointCollection"));
        }
    
        private void Window_LocationChanged(object sender, EventArgs e)
        {
            if (this.IsLoaded)
            {
                Random rnd = new Random();
                Point Point1 = new Point(rnd.Next(50, 200), rnd.Next(50, 200));
                Point Point2 = new Point(rnd.Next(50, 200), rnd.Next(50, 200));
                Point Point3 = new Point(rnd.Next(50, 200), rnd.Next(50, 200));
                ResetPolygon(Point1, Point2, Point3);
            }
    
        }
    }
    
    public class MyPointCollectionConverter : IValueConverter
    {
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var regPtsColl = new PointCollection(); //regular points collection.
            var obsPtsColl = (ObservableCollection<Point>)value; //observable which is used to raise INCC event.
            foreach (var point in obsPtsColl)
                regPtsColl.Add(point);
            return regPtsColl;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    
        #endregion
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get a more dynamic solution than naming all dropdowns
Figured it out myself, solution below. I'm trying to save a dynamic number of
Solution Found: Dynamic array keys I have a multi dimensional dynamic array, the format
I have to create a stored procedure using a Dynamic SQL solution because I
I am looking for a solution to dynamic configure the routing in ASP.NET MVC
I'm figuring out a possible solution for a dynamic crossfade of HTML elements. The
I'm still searching solution for getting values from dynamic created object. Follwing code generates
I want to create a Dynamic aspx Page in current solution through code-behind..forexample i
I need a solution for caching PHP info on a dynamic page AND include
I am trying to use the Dynamic Data Display library for WPF in my

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.