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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:32:37+00:00 2026-05-23T16:32:37+00:00

I have the following DependencyProperty in a Silverlight UserControl: public static readonly DependencyProperty ColumnsProperty

  • 0

I have the following DependencyProperty in a Silverlight UserControl:

public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register( "Columns", typeof( ObservableCollection<FilterableDataGridColumn> ), typeof( FilterableDataGridControl ), new PropertyMetadata( new ObservableCollection<FilterableDataGridColumn>(), new PropertyChangedCallback( OnColumnsChanged ) ) );

public ObservableCollection<FilterableDataGridColumn> Columns {
    get {
        return ( ObservableCollection<FilterableDataGridColumn> )GetValue( ColumnsProperty );
    }
    set {
        SetValue( ColumnsProperty, value );
    }
}

static void OnColumnsChanged( object sender, DependencyPropertyChangedEventArgs args ) {
    ...
}

I’m trying to initialize it from xaml:

<my:FilterableDataGridControl ... >
    <my:FilterableDataGridControl.Columns>
        <my:FilterableDataGridColumn Header="Name" PropertyName="Name" ColumnType="Text" />
        <my:FilterableDataGridColumn Header="Type" PropertyName="Type" ColumnType="Text" />
    </my:FilterableDataGridControl.Columns>
</my:FilterableDataGridControl>

But it doesn’t work! No exception, no error, but the OnColumnsChanged is not invoked.

Any idea?

  • 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-23T16:32:38+00:00Added an answer on May 23, 2026 at 4:32 pm

    I mocked up your example in full and basically you are expecting a property change event to occur for the content changes of an ObservableCollection. Your event handler is only triggered if the collection itself is replaced, whereas you are replacing child elements only and not the collection.

    The only piece of your code that will get hit is the getter:

    get { return (ObservableCollection<FilterableDataGridColumn>)GetValue(ColumnsProperty); }
    

    There may be a more graceful way to hookup events to dynamically created properties, but this will work:

        public ObservableCollection<FilterableDataGridColumn> Columns
        {
            get
            {
                var columns = (ObservableCollection<FilterableDataGridColumn>)GetValue(ColumnsProperty);
                columns.CollectionChanged -= columns_CollectionChanged; // Disconnect each time we reconnect
                columns.CollectionChanged += columns_CollectionChanged;
                return columns;
            }
            set
            {
                var columns = (ObservableCollection<FilterableDataGridColumn>)GetValue(ColumnsProperty);
                if (columns != null)
                {
                    columns.CollectionChanged -= columns_CollectionChanged; // Disconnect each time we change collection
                }
                SetValue(ColumnsProperty, value);
            }
        }
    
        void columns_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            // This will get hit
        }
    

    This is adding a CollectionChanged hander to the collection, rather than listening for the collection itself to be replaced.

    *You will note the setter goes to the trouble of removing the hander from any previous collection. This is a “just in case” measure as otherwise a collection disconnected from this property would still report changes after removal. This is not required to make it work for the initial collection your property adds

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

Sidebar

Related Questions

I have the following declaration: public static readonly DependencyProperty PassColorProperty = DependencyProperty.RegisterAttached(PassColor, typeof(string), typeof(ColorMasking),
Say I have the following Code: public static DependencyProperty LabelProperty = DependencyProperty.RegisterAttached( Label, typeof(Label),
I have the following code: public partial class NewWindow: Window { public static readonly
I have custom control with following: <TextBox Grid.Column=3 Text={TemplateBinding SampleValue} /> public static readonly
I have the following in C#: public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double
I have the following dependency property inside a class: class FooHolder { public static
I have a UserControl with the following Property: public List<Rect> HotSpots { get {
I have the following class schema public Class Test : DependencyObject { private DependencyProperty
I have a UserControl (AgreementDetails) in WPF with the following DependencyProperty and function: //
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>

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.