c# - WPF - DependencyProperty ignoring setter with side-effects on change -


this question has answer here:

i have wpf user control wrapper 2 other controls, showing 1 of them depending on situation. possesses itemssource property sets itemssource 2 underlying controls. want make property can bound on .xaml file.

i created dependencyproperty, , i've changed getter , setter use it. however, when debug code, can see setter never getting called. can see dependency property changing value, it's not setting underlying controls' properties.

how can make underlying controls have properties set when dependency property changes?

public partial class accountselector : usercontrol {     public static readonly dependencyproperty itemssourceproperty = dependencyproperty.register(         "itemssource", typeof(ienumerable), typeof(accountselector));     public ienumerable itemssource     {                 {             return (ienumerable)getvalue(itemssourceproperty);         }         set         {             if (usecombobox)                 acccombo.itemssource = value;             else                 acccomplete.itemssource = value;             setvalue(itemssourceproperty, value);         }     } } 

you have pass propertychangedcallback uipropertymetadata, this:

    public static readonly dependencyproperty itemssourceproperty = dependencyproperty.register(         "itemssource", typeof(ienumerable), typeof(accountselector), new uipropertymetadata((d, e) =>         {             if (e.newvalue == null) return;              var s = d accountselector;             var list = e.newvalue ienumerable;              if (list == null || s == null) return;             if (s.usecombobox)                 s.acccombo.itemssource = list;             else                 s.acccomplete.itemssource = list;                         }));     public ienumerable itemssource     {                 {             return (ienumerable)getvalue(itemssourceproperty);         }         set         {             setvalue(itemssourceproperty, value);         }     } 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -