wpf - How to link scrollbar and scrollviewer -


i have 2 scrollviewer's containing alternate views of same collection. have bound scrolling of 2 scrollviewers handling scrollchanged event , using scrolltoverticaloffset.

for presentation reasons have set both scrollviewer scrollbars hidden , want control them both seperate scrollbar.

this seems not straightforward. recall seeing blog few months ago can't find again.

can point me in direction of useful resources or give me shove in right direction how might achieved.

thanks in advance.

great, needed. extended bit scrollviewer can set xaml using dependency property. in xaml:

<local:bindablescrollbar boundscrollviewer ="{binding elementname=scrollviewer}"  orientation="vertical" /> 

code:

    /// <summary> /// extended scrollbar can bound external scrollviewer. /// </summary> public class bindablescrollbar : scrollbar {     public scrollviewer boundscrollviewer     {         { return (scrollviewer)getvalue(boundscrollviewerproperty); }         set { setvalue(boundscrollviewerproperty, value); }     }      // using dependencyproperty backing store boundscrollviewer.  enables animation, styling, binding, etc...     public static readonly dependencyproperty boundscrollviewerproperty =         dependencyproperty.register("boundscrollviewer", typeof(scrollviewer), typeof(bindablescrollbar), new frameworkpropertymetadata(null, new propertychangedcallback(onboundscrollviewerpropertychanged)));      private static void onboundscrollviewerpropertychanged(dependencyobject d, dependencypropertychangedeventargs e)     {         bindablescrollbar sender = d bindablescrollbar;         if (sender != null && e.newvalue != null)         {             sender.updatebindings();         }     }        /// <summary>     /// initializes new instance of <see cref="bindablescrollbar"/> class.     /// </summary>     /// <param name="scrollviewer">the scroll viewer.</param>     /// <param name="o">the o.</param>     public bindablescrollbar(scrollviewer scrollviewer, orientation o)         : base()     {          this.orientation = o;         boundscrollviewer = scrollviewer;      }      /// <summary>     /// initializes new instance of <see cref="bindablescrollbar"/> class.     /// </summary>     public bindablescrollbar() : base() { }      private void updatebindings()     {         addhandler(scrollbar.scrollevent, new scrolleventhandler(onscroll));         boundscrollviewer.addhandler(scrollviewer.scrollchangedevent, new scrollchangedeventhandler(boundscrollchanged));         minimum = 0;         if (orientation == orientation.horizontal)         {             setbinding(scrollbar.maximumproperty, (new binding("scrollablewidth") { source = boundscrollviewer, mode = bindingmode.oneway }));             setbinding(scrollbar.viewportsizeproperty, (new binding("viewportwidth") { source = boundscrollviewer, mode = bindingmode.oneway }));         }         else          {             this.setbinding(scrollbar.maximumproperty, (new binding("scrollableheight") { source = boundscrollviewer, mode = bindingmode.oneway }));             this.setbinding(scrollbar.viewportsizeproperty, (new binding("viewportheight") { source = boundscrollviewer, mode = bindingmode.oneway }));          }          largechange = 242;          smallchange = 16;     }      private void boundscrollchanged(object sender, scrollchangedeventargs e)      {          switch (this.orientation)          {              case orientation.horizontal:                 this.value = e.horizontaloffset;             break;             case orientation.vertical:                 this.value = e.verticaloffset;                  break;              default:                 break;          }     }      private void onscroll(object sender, scrolleventargs e)      {         switch (this.orientation)          {             case orientation.horizontal:                 this.boundscrollviewer.scrolltohorizontaloffset(e.newvalue);                 break;             case orientation.vertical:                 this.boundscrollviewer.scrolltoverticaloffset(e.newvalue);                 break;              default:                  break;          }      } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -