views:

19

answers:

1

I have dependency property in my UserControl "Menu":

internal static readonly DependencyProperty ActionProperty = 
     DependencyProperty.RegisterAttached(
     "Action", 
     typeof(LetterAction), 
     typeof(Menu), 
     new FrameworkPropertyMetadata(LetterAction.None, ActionChanged));

I set this property into control:

<my:RibbonButton x:Name="buttonOpen" Label="Open" c:Menu.Action="Open" />

I want to take in my Menu control collection of controls which have Menu.Action. How can I do it without static collection?

P.S. It needs for subscribing on Click event of control that has setted Action property.

A: 

In your PropertyChanged handler you can maintain a collection of each object that sets the property.

private static List<DependencyObject> _haveAction = new List<DependencyObject>();
private static void ActionChanged(DependencyObject dObj, DependencyPropertyChangedEventArgs e)
{
    if (!_haveAction.Contains(dObj))
        _haveAction.Add(dObj);
}
John Bowen
Sorry, I need a non-static collection.
Rover