Senkwe Chanda

Hi all,

Here's my dillema. I'm using a scroll viewer that needs to be manipulated by a pair of templated repeat buttons.

Here's some pseudo-code that shows my scrollviewer

<ScrollViewer Name="scroller" Grid.Row="1">
 <ScrollViewer.Template>
  <ControlTemplate TargetType="{x:Type ScrollViewer}">
   <ScrollContentPresenter Grid.Row="1" Content="{TemplateBinding Content}"/>
  </ControlTemplate> 
 </ScrollViewer.Template>
 
 <ItemsControl ItemTemplate="{StaticResource blah}" ItemsSource="{Binding Path=blahPath, Mode=Default}" Name="myWrapPanel" >
       <ItemsControl.ItemsPanel>
         <ItemsPanelTemplate>
           <WrapPanel />
         </ItemsPanelTemplate>
       </ItemsControl.ItemsPanel>
      </ItemsControl>
</ScrollViewer>

<RepeatButton x:Name="btn_scrollUp"/>
<RepeatButton x:Name="btn_scrollDown"/>

 

so...my question is, is there anyway for me map my scrollviewers LineUp and LineDown commands to my repeat buttons

I've tried something like...

<RepeatButton x:Name="btn_scrollUp" Command="{Binding ElementName=scroller, Path=ScrollBar.LineUpCommand}"/>

But that doesn't work.

I don't want to use a regular button with a click event because I need the characteristics of  a repeat button.

Any ideas

Thanks.


 



Re: Windows Presentation Foundation (WPF) Binding to the ScrollBar.LineXXXCommand of a scroll viewer?

ivolved_Mike_Brown

Try setting the CommandTarget on the RepeatButton to your ScrollBar

<RepeatButton
x:Name="btn_scrollUp"
Command="ScrollBar.LineUpCommand"
CommandTarget="{Binding ElementName=scroller}"/>

This should do it for you!






Re: Windows Presentation Foundation (WPF) Binding to the ScrollBar.LineXXXCommand of a scroll viewer?

dontera

Hey there,

I feel your pain.. I attempted to do something similar (with a Slider / ScrollViewer rather than RepeatButton).

While my situation is dissimilar, perhaps my solution will give you some ideas..


First I created a custom scrollviewer class and added the following property:

public double MyVerticalOffset
{
get { return this.VerticalOffset; }
set { this.ScrollToVerticalOffset(value); }
}

Then in my XAML for the window I add the binding to the Slider

<local:MyScrollViewer x:Name="scroller" ... />
<local:MySlider x:Name="slider" ....
Value="{Binding Path=MyVerticalOffset, ElementName=scroller}" />

Then in my window I wired up the following event

Window1.AddHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(scroller_ScrollChanged));

and to align the Slider Thumb and maximum scroll values I have this:

void scroller_ScrollChanged(object sender, RoutedEventArgs e)
{
...
slider.Value = scroller.MyVerticalOffset;
slider.Maximum = scroller.ExtentHeight;
}


Hope this can help you in some way.

Forrest




Re: Windows Presentation Foundation (WPF) Binding to the ScrollBar.LineXXXCommand of a scroll viewer?

Senkwe Chanda

Mike, thanks alot...that actually did the trick perfectly



Re: Windows Presentation Foundation (WPF) Binding to the ScrollBar.LineXXXCommand of a scroll viewer?

Senkwe Chanda

Thanks dontera, looks like we were trying to solve slightly different problems though