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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:48+00:00 2026-05-23T10:53:48+00:00

This question deals entirely with code and no XAML. So I have this class,

  • 0

This question deals entirely with code and no XAML.

So I have this class, called Location:

public class Location
{
    public int id { get; set; }
    public double latitude { get; set; }
    public double longitude { get; set; }
    public string name { get; set; }
    public string type { get; set; }
    public bool isAnOption { get; set; }

    public Location(int newId, double newLatitude, double newLongitude, string newName, string newType)
    {
        id = newId;
        latitude = newLatitude;
        longitude = newLongitude;
        name = newName;
        type = newType;
        isAnOption = true;
    }

    public System.Windows.Shapes.Ellipse createIcon()
    {
        System.Windows.Shapes.Ellipse icon = new System.Windows.Shapes.Ellipse();
        SolidColorBrush brush;
        if (isAnOption)
        {
            brush = new SolidColorBrush(Colors.Blue);
        }
        else
        {
            brush = new SolidColorBrush(Colors.Red);
        }
        brush.Opacity = 0.5;
        icon.Fill = brush;
        icon.Height = icon.Width = 44;
        icon.HorizontalAlignment = HorizontalAlignment.Left;
        icon.VerticalAlignment = VerticalAlignment.Top;

        Thickness locationIconMarginThickness = new Thickness(0, 0, 0, 0);
        locationIconMarginThickness.Left = (longitude - 34.672852) / (35.046387 - 34.672852) * (8704) - 22;
        locationIconMarginThickness.Top = (32.045333 - latitude) / (32.045333 - 31.858897) * (5120) - 22;
        icon.Margin = locationIconMarginThickness;

        Label labelName = new Label();
        labelName.Content = name;

        StackPanel locationData = new StackPanel();
        locationData.Children.Add(labelName);

        ToolTip toolTip = new ToolTip();
        toolTip.Content = locationData;

        icon.ToolTip = toolTip;

        return icon;
    }
}

Pretty straight forward. Notice the createIcon method.

Now, in the MainWindow (it’s a WPF project), I declare List<Location> locations and fill it up with data.

At some point I put the “icons” on an existing GridScroller like so:

gridScroller.Children.Add(location.createIcon()); 

Now, the problem I have is I want to bind the property isAnOption of Location to the color of the brush of a corresponding icon’s brush’s color. In other words, when the property isAnOption of a certain object derived from Location is changed, I would like that change to reflect in the color of the ellipse that’s on the GridScroller.
Help please.

Thanks

  • 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-23T10:53:48+00:00Added an answer on May 23, 2026 at 10:53 am

    First, your Location class would need to implement INotifyPropertyChanged, so any bindings that use isAnOption as a source will be notified when it is changed.

    Then you can bind the Fill property to your property like so:

    Binding binding = new Binding("isAnOption") {
        Source = this,
        Converter = new MyConverter(),
    };
    icon.SetBinding(Ellipse.FillProperty, binding);
    

    Finally, MyConverter would be a custom IValueConverter that returns a Blue or Red brush based on the bool value passed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question deals with teamwork and emails. I'm facing the following scenario. I have
I know this SO question, but it deals with the subject in more general
This question might be naive as I'm new to ColdFusion programming. I have a
The other answers to this question deal with timing whereas with this problem deals
This question deals with optional arguments passed to a Ruby block. I'm wondering if
This question deals with concurrency issues, for suggestions on how to display a busy
NOTE: This question deals with an issue observed back in 2011 with an old
This related question deals with the retrieval of an app's build date in C#,
This question deals mainly with streams in web application in .net. In my webapplication
This question is purely theoretical. I was wondering whether the Linux source code could

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.