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

  • Home
  • SEARCH
  • 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 74479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:21:53+00:00 2026-05-10T20:21:53+00:00

I have a class like this: public class Stretcher : Panel { public static

  • 0

I have a class like this:

public class Stretcher : Panel {      public static readonly DependencyProperty StretchAmountProp = DependencyProperty.RegisterAttached('StretchAmount', typeof(double), typeof(Stretcher), null);      public static void SetStretchAmount(DependencyObject obj, double amount)     {         FrameworkElement elem = obj as FrameworkElement;         elem.Width *= amount;          obj.SetValue(StretchAmountProp, amount);     } } 

I can set the stretch amount property in XAML using the attribute syntax:

<UserControl x:Class='ManagedAttachedProps.Page'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:map='clr-namespace:ManagedAttachedProps'     Width='400' Height='300'>      <Rectangle Fill='Aqua' Width='100' Height='100' map:Stretch.StretchAmount='100' />  </UserControl> 

and my rectangle is stretched, but I can’t use property element syntax like this:

<UserControl x:Class='ManagedAttachedProps.Page'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:map='clr-namespace:ManagedAttachedProps'     Width='400' Height='300'>      <Rectangle Fill='Aqua' Width='100' Height='100'>         <map:Stretcher.StretchAmount>100</map:Stretcher.StretchAmount>     </Rectangle> </UserControl> 

with the property element syntax my set block seems to be totally ignored (I can even put invalid double values in there), and the SetStretchAmount method is never called.

I know it’s possible to do something like this, because VisualStateManager does it. I’ve tried using types other than double and nothing seems to work.

  • 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. 2026-05-10T20:21:53+00:00Added an answer on May 10, 2026 at 8:21 pm

    I think I figured this out, although I’m not totally sure I understand the reason why it works.

    In order to get your example to work I had to create a custom type called Stretch with a property called StretchAmount. Once I did that and put that inside the property element tags it worked. Otherwise it wasn’t called.

    public class Stretch {     public double StretchAmount { get; set; } } 

    And the property changed to..

    public static readonly DependencyProperty StretchAmountProp = DependencyProperty.RegisterAttached('StretchAmount', typeof(Stretch), typeof(Stretcher), null);  public static void SetStretchAmount(DependencyObject obj, Stretch amount)  {      FrameworkElement elem = obj as FrameworkElement;      elem.Width *= amount.StretchAmount;      obj.SetValue(StretchAmountProp, amount);  } 

    To get this to work in the scenario where you aren’t using a property element you would need to create a custom type converter to allow this to work.

    Hope this helps, even though it doesn’t explain the why which I’m still trying to understand.

    BTW – for a real brain teaser, take a look at the VisualStateManager in reflector. The dependency property and the setter for VisualStateGroups are both internal.

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

Sidebar

Ask A Question

Stats

  • Questions 256k
  • Answers 256k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have used django's other inheritance methods because I hit… May 13, 2026 at 10:30 am
  • Editorial Team
    Editorial Team added an answer just use log4net if you want to configure your log… May 13, 2026 at 10:30 am
  • Editorial Team
    Editorial Team added an answer Does it HAVE to be an integer? Could it be… May 13, 2026 at 10:30 am

Related Questions

I'm writing a small Silverlight media player application. In the top of the page
I can't for the life of me figure out why this doesn't work. I've
I'm databinding a listbox to an object that contains two array of strings. Each
I am working with a team on LoB application. We would like to have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.