WPF Range Slider not binding -


i seem have same problem implementation of rangeslider (or more simply, slider 2 thumbs).

i want bind both thumbs datacontext , have binding 2-way. unfortunately, seem able bind set sliders' positions. if move them mouse lose binding.

i have used several range sliders, keep simple, in example i'm using 1 thejoyofcode.com. (i haven't modified it, i'm not including here now, can if helps). consume using xaml below, intention of letting framework sliders (named "minslider" , "maxslider") bound same datasources.

when move framework sliders, of bound items follow them, including range slider, if move 1 of thumbs on range slider not update datasource or framework slider.

my window xaml...

        <separator></separator>          <controls:rangeslider x:name="slider"                                minimum="10"                               maximum="20"                               lowervalue="{binding min, updatesourcetrigger=propertychanged}"                               uppervalue="{binding max, updatesourcetrigger=propertychanged}"                               />         <textblock text="{binding lowervalue, elementname=slider}"/>         <textblock text="{binding uppervalue, elementname=slider}"/>          <separator></separator>          <slider x:name="maxslider" minimum="10" maximum="20" value="{binding max}"/>         <textblock text="{binding value, elementname=maxslider}"/>          <separator></separator>          <textblock text="{binding min}"/>         <textblock text="{binding max}"/>     </stackpanel> </window> 

...and mysource class...

public class mysource : inotifypropertychanged {     private double _min;     public double min     {         { return _min; }         set         {             _min = value;             raisepropertychanged("min");         }     }      private double _max;     public double max     {         { return _max; }         set         {             _max = value;             raisepropertychanged("max");         }     }      public event propertychangedeventhandler propertychanged;      protected virtual void onpropertychanged(propertychangedeventargs e)     {         var handler = this.propertychanged;         if (handler != null)         {             handler(this, e);         }     }      protected void raisepropertychanged(string propertyname)     {         onpropertychanged(new propertychangedeventargs(propertyname));     }  } 

it because need set bindingmode=twoway in bindings.

a control author can make default behavior (the wpf slider this), unless dependency property registered frameworkpropertymetadata.bindstwowaybydefault, oneway mode used.

msdn explains bindingmodes.


Comments