Click here to Skip to main content
15,887,135 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: How to Programatically click a Button on a navigated Frame Page Pin
Vimalsoft(Pty) Ltd14-Jan-16 5:40
professionalVimalsoft(Pty) Ltd14-Jan-16 5:40 
QuestionCustom FrameworkElement with child controls Pin
Kenneth Haugland12-Jan-16 7:51
mvaKenneth Haugland12-Jan-16 7:51 
AnswerRe: Custom FrameworkElement with child controls Pin
Gerry Schmitz12-Jan-16 17:06
mveGerry Schmitz12-Jan-16 17:06 
GeneralRe: Custom FrameworkElement with child controls Pin
Kenneth Haugland13-Jan-16 1:39
mvaKenneth Haugland13-Jan-16 1:39 
GeneralRe: Custom FrameworkElement with child controls Pin
Gerry Schmitz13-Jan-16 6:25
mveGerry Schmitz13-Jan-16 6:25 
QuestionBinding a CompositeCollection to a Canvas (C#) Pin
Kenneth Haugland8-Jan-16 22:31
mvaKenneth Haugland8-Jan-16 22:31 
AnswerRe: Binding a CompositeCollection to a Canvas (C#) Pin
Kenneth Haugland9-Jan-16 2:42
mvaKenneth Haugland9-Jan-16 2:42 
AnswerRe: Binding a CompositeCollection to a Canvas (C#) Pin
Richard Deeming11-Jan-16 3:51
mveRichard Deeming11-Jan-16 3:51 
Kenneth Haugland wrote:
how many instances will share this value?

All of them. The value in a static field is shared across the whole AppDomain *.

Wouldn't it be simpler to get rid of the references dictionary, and make your collectionChangedHandler method an instance method?

Something like this should work:
C#
private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var canvas = (MyCanvas)d;
    canvas.OnItemsSourcePropertyChanged(e);
}

protected virtual void OnItemsSourcePropertyChanged(DependencyPropertyChangedEventArgs e)
{
    repopulateChildren(this);
    
    var compositeCollection = e.OldValue As CompositeCollection;
    if (compositeCollection != null)
    {
        foreach (CollectionContainer item in compositeCollection)
        {
            var elements = (ObservableCollection<UIElement>)item.Collection;
            elements.CollectionChanged -= collectionChangedHandler;
        }
    }
    else
    {
        var elements = e.OldValue as INotifyCollectionChanged;
        if (elements != null)
        {
            elements.CollectionChanged -= collectionChangedHandler;
        }
    }

    compositeCollection = e.NewValue As CompositeCollection;
    if (compositeCollection != null)
    {
        foreach (CollectionContainer item in compositeCollection)
        {
            var elements = (ObservableCollection<UIElement>)item.Collection;
            elements.CollectionChanged += collectionChangedHandler;
        }
    }
    else
    {
        var elements = e.NewValue as INotifyCollectionChanged;
        if (elements != null)
        {
            elements.CollectionChanged += collectionChangedHandler;
        }
    }
}

private void collectionChangedHandler(object sender, NotifyCollectionChangedEventArgs e)
{
    ...
}



* Unless the field is marked with the ThreadStatic attribute[^], in which case it's specific to a thread. But that wouldn't help you in this case.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Binding a CompositeCollection to a Canvas (C#) Pin
Kenneth Haugland11-Jan-16 4:34
mvaKenneth Haugland11-Jan-16 4:34 
QuestionCan I run UITests on a WPF application. Pin
James_Parsons8-Jan-16 4:56
James_Parsons8-Jan-16 4:56 
AnswerRe: Can I run UITests on a WPF application. Pin
NickPace8-Jan-16 5:06
NickPace8-Jan-16 5:06 
QuestionLabel does not Get Updated Pin
Vimalsoft(Pty) Ltd6-Jan-16 20:33
professionalVimalsoft(Pty) Ltd6-Jan-16 20:33 
AnswerRe: Label does not Get Updated Pin
Mycroft Holmes6-Jan-16 20:45
professionalMycroft Holmes6-Jan-16 20:45 
GeneralRe: Label does not Get Updated Pin
Vimalsoft(Pty) Ltd6-Jan-16 20:49
professionalVimalsoft(Pty) Ltd6-Jan-16 20:49 
GeneralRe: Label does not Get Updated Pin
Mycroft Holmes6-Jan-16 21:04
professionalMycroft Holmes6-Jan-16 21:04 
GeneralRe: Label does not Get Updated Pin
Vimalsoft(Pty) Ltd6-Jan-16 21:09
professionalVimalsoft(Pty) Ltd6-Jan-16 21:09 
QuestionWPF/MVVM Unit Test Questions Pin
Kevin Marois5-Jan-16 5:46
professionalKevin Marois5-Jan-16 5:46 
AnswerRe: WPF/MVVM Unit Test Questions Pin
Pete O'Hanlon5-Jan-16 5:58
mvePete O'Hanlon5-Jan-16 5:58 
GeneralRe: WPF/MVVM Unit Test Questions Pin
Kevin Marois5-Jan-16 6:02
professionalKevin Marois5-Jan-16 6:02 
GeneralRe: WPF/MVVM Unit Test Questions Pin
Pete O'Hanlon5-Jan-16 8:26
mvePete O'Hanlon5-Jan-16 8:26 
GeneralRe: WPF/MVVM Unit Test Questions Pin
Mycroft Holmes6-Jan-16 20:49
professionalMycroft Holmes6-Jan-16 20:49 
GeneralRe: WPF/MVVM Unit Test Questions Pin
Pete O'Hanlon6-Jan-16 21:06
mvePete O'Hanlon6-Jan-16 21:06 
GeneralRe: WPF/MVVM Unit Test Questions Pin
Mycroft Holmes7-Jan-16 12:03
professionalMycroft Holmes7-Jan-16 12:03 
GeneralRe: WPF/MVVM Unit Test Questions Pin
Pete O'Hanlon7-Jan-16 21:37
mvePete O'Hanlon7-Jan-16 21:37 
Questionwhat is the best way to save images to print in wpf Pin
neodeaths5-Jan-16 4:12
neodeaths5-Jan-16 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.