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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:47:34+00:00 2026-05-26T08:47:34+00:00

Recently i was developing a custom control in Silverlight, I created custom dependency property

  • 0

Recently i was developing a custom control in Silverlight, I created custom dependency property which is of type ObservableCollection. I have another 2 custom dependency properties of type strings. My requirement is on addition of any item to collection, I have to fire collectionChanged Event , in this event handler, i want to update the other 2 dependency properties.

public static readonly DependencyProperty itemsProperty = DependencyProperty.Register("Items", typeof(ObservableCollection<ValidationErrorMessage>), typeof(SummaryUserControl), new PropertyMetadata(new ObservableCollection<ValidationErrorMessage>(), new PropertyChangedCallback(fun1)));
    public ObservableCollection<ValidationErrorMessage> Items
    {
        get
        {
            return (ObservableCollection<ValidationErrorMessage>)base.GetValue(itemsProperty);
        }
        set
        {

            base.SetValue(itemsProperty, value);
        }
    }


public static void fun1(object sender, DependencyPropertyChangedEventArgs       evt)
    {
        var newValue =   evt.NewValue as ObservableCollection<ValidationErrorMessage>;

        if(newValue!=null)
            newValue.CollectionChanged += new NotifyCollectionChangedEventHandler(CollectionChangedHandler);

        var oldValue  = evt.OldValue as ObservableCollection<ValidationErrorMessage>;
        if(oldValue!=null)
            oldValue.CollectionChanged -= new NotifyCollectionChangedEventHandler(CollectionChangedHandler);
    }

    static void CollectionChangedHandler(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
           var newItems =     e.NewItems as ObservableCollection<ValidationErrorMessage>;
           foreach (var item in newItems)
            {
                item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
            }
        }
    }

    static void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {

    }



public static readonly DependencyProperty headerProperty = DependencyProperty.Register("Header", typeof(String), typeof(SummaryUserControl), new PropertyMetadata(String.Empty, null));
    public String Header
    {
        get
        {
            return (String)base.GetValue(headerProperty);
        }
        set
        {
            base.SetValue(headerProperty, value);
            RaisePropertyChange("Header");
        }
    }

    public static readonly DependencyProperty messageTypeProperty =
    DependencyProperty.Register("MessageType", typeof(MessageEnumType), typeof(SummaryUserControl), new PropertyMetadata(MessageEnumType.Error, null));
    public MessageEnumType MessageType
    {
        get { return (MessageEnumType)GetValue(messageTypeProperty); }
        set { SetValue(messageTypeProperty, value); RaisePropertyChange("MessageType"); }
    }

How can I change the values of the dependency properties messageType and Header? I’m unable to access those properties in either the CollectionChanged or NotifyPropertyChanged event since all those events are static. I cannot access the instance within these static event handlers.

I tried to fix the problem with a converter, but my curosity on Silverlight makes me want to use the above approach. How can I set values for those dependency properties within CollectionChanged event or NotifyPropertyChanged events?

  • 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-26T08:47:35+00:00Added an answer on May 26, 2026 at 8:47 am

    The sender in your static fun1 method should be the instance of the class which declares the itemsProperty DependencyProperty. Therefore you can access the concrete instance with casting the sender to your class.

    public static void fun1(object sender, DependencyPropertyChangedEventArgs       evt) 
    {
         MyClass concreteInstance = sender as MyClass;
         if(concreateInstance != null)
         {
             [...your code...]
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I was developing a custom jQuery-based content slider, which unlike most other sliders
I have recently been developing a website which relies a large part on the
I've recently started developing my first serious application which uses a SQL database, and
I recently launched a website I have been developing over the past year -
I have just recently discovered how much I enjoy developing code the TDD way:
I have been experimenting recently with Silverlight, RIA Services, and Entity Framework using .NET
I've recently been developing on the django platform and have stumbled upon Django Forms
So we have recently started developing applications for the iPad for our company. Unfortunately
I have recently been developing a website for a company, with a full administration
I have started developing a webpage and recently hired someone to write code to

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.