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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:44:05+00:00 2026-05-13T13:44:05+00:00

How do I add my property called weight to an image and use it

  • 0

How do I add my property called weight to an image and use it like this:?

myImage.weight

(assuming i have already defined myImage in XAML)

here’s my code:

public partial class MainWindow : Window
{
    public double Weight
    {
        get
        {
            return (double)GetValue(WeightProperty);
        }
        set
        {
            SetValue(WeightProperty, value);
        }
    }
    public static readonly DependencyProperty WeightProperty = DependencyProperty.Register("Weight", typeof(Double), typeof(Image));


    public MainWindow()
    {
        this.InitializeComponent();
                    myImage.Weight = 2;'

here the last line doesn’t work because the property Weight does not attach to myImage.

This below also doesn’t work in XAML:

<Image x:Name="myImage" Weight="2" />
  • 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-13T13:44:05+00:00Added an answer on May 13, 2026 at 1:44 pm

    I would recommend just inheriting the Image class and adding your new dependency property.

    Eg.

    public class MyImage : System.Windows.Controls.Image
    {
        public double Weight
        {
            get { return (double)GetValue(WeightProperty); }
            set { SetValue(WeightProperty, value); }
        }
    
        // Using a DependencyProperty as the backing store for Weight.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WeightProperty =
            DependencyProperty.Register("Weight", typeof(double), typeof(MyImage), new UIPropertyMetadata(0.0));
    
    }
    

    Then in your XAML code, with this local namespace:

    xmlns:local="clr-namespace:[LIBRARYNAME]"
    

    you can use:

    <local:MyImage Weight="10.0"/>
    

    It’s a tad cumbersome, but I think it gives you the most control.

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

Sidebar

Related Questions

How do you use the CSS content property to add HTML entities? Using something
I would like to do something like add a nice-to-Excel-functions Name property to the
i have a class based on TInterfacedObject. i add it to TTreeNode's Data property.
I'm trying to add a property called enabled? to a model with both a
Lets say we have a class with a property called PetsName. If it is
I have an object Proposal which has a property called CurrentAgency of Agency which
I have page gets given an ArrayList<Document> where each document has a property called
I want to add a property to my User model that returns the number
I'm trying to add a custom property which is a guid, but it gives
In SQL Server (in my case, 2005) how can I add the identity property

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.