Scroll event for Windows Phone ScrollViewer - c#

In my Windows Phone 8 application I am trying to implement a custom control that behaves like the built-in calendar control which displays the current date above the scrollable content (daily views). Initially I have tried to use the LongListSelector control (which gives me the hierarchical view), but I am not able to determine the scroll position and therefore cannot update the header (the date in the case of the calendar control).
So I switched to using a ScrollViewer control which contains a StackPanel with different controls inside.
Whenever the user scrolls the content I would like to be notified so I can update the UI relative to the content being shown. However, the ScrollViewer doesn't have any explicit scrolling events.
I have tried to use the LayoutUpdated event (which seems to get called frequently enough for my purposes), but when I then update the UI in the event handler another LayoutUpdated event is raised and an infinite loop is created.
How can I update the UI based on the scroll position?

I have no idea, But check this links, this may help.
Get scroll event for ScrollViewer on Windows Phone
http://social.msdn.microsoft.com/Forums/silverlight/en-US/b1cdf697-ed37-4d3a-9f3c-46338bdc92b4/how-to-get-a-scroll-event-from-a-scrollviewer?forum=silverlightbugs

Related

MouseWheel event doesn't fire on a non-Selectable Control

I have written a custom Control, based on other code, which includes a call to SetStyle(ControlStyles.Selectable, false);
This prevents the following code from being called (which works if I remove the above line and click on the Control first to 'focus' it):
protected override void OnMouseWheel(MouseEventArgs e)
{
ScrollBar.Value = Math.Min(ScrollBar.Value - e.Delta, ScrollBar.Maximum - ScrollBar.LargeChange);
LayoutChanged();
}
My control does not need focus so Selectable=false is correct.
What do I need to do so that I can run this code whenever the mouse is over my control and the MouseWheel is moved regardless of where the focus is?
Thanks for the comments. A additional info:-
I am running Windows 7 but any solution must work on any OS.
The Control is inherited via Control/ControlBase/BaseControl/BaseStyleControl where the latter 3 are DevExpress controls.
The real focus should not be changed just because the cursor hovers over my control
There are no child controls other than a scrollbar (an inherited DevExpress one) which is normally invisible and shows itself when the mouse hovers over where it would be when visible.
The control does nothing but draw itself (imagine a number of bookshelves one under the other with book covers drawn on them - the number of shelves increases to accommodate all the books and the scrollbar allows all to be scrolled into view.
Since this is a use-anywhere Control, getting MouseWheel events from a Parent that knows about its requirements isn't a good idea.
Maybe there is a way of registering for a first-look (is that a MessagePreview?) to pinch MouseWheel events before normal processing happens.

WPF ScrollViewer Changed Event fired automatically

As per requirement need in C# WPF application , We want to load Data on scrollViewer while moving Horizontal scroll bar.
As we have tried by scrollViewer_ScrollChanged event. But It fired automatically every time while loading of scrollViewer.
In our case we have one grid control inside scrollViewer.
Please help me, looking for positive reply.

How to determine when ScrollViewer started scrolling?

I'm using a Windows Phone 8.1 project and have a ScrollViewer in my XAML.
Is there an event which will fire when the ScrollViewer start scrolling? Or anyway to trigger code when ScrollViewer start scrolling?
Try ViewChanging and ViewChanged events of ScrollViewer.
Note that these events will be called multiple times during a touch manipulation. You will need to rely on IsIntermediate (in ScrollViewerViewChangedEventArgs) or IsInertial (in ScrollViewerViewChangingEventArgs) to call your code accordingly.
Update
If you want to know when a touch happens immediately I'd give the ScrollViewer's direct child, for example, a StackPanel a transparent background and then subscribe to its PointerEntered event.

Make Multiple Controls Use Same Tool Tip Message (c# Client App.)

I would like the same tool tip message (the one entered in the "ToolTip on myControlId" field) to be displayed when the mouse is hovered over an area which contains multiple controls. I tried putting the controls inside a Panel and GroupBox, but it only works when the mouse is in the "white space" area of the Panel/GroupBox, and, of course, does not work when the mouse is on a control within the Panel/GroupBox.
I'm from the web dev world so I'm open to suggestions for a new approach if I'm going about this the wrong way.
In standart windows developmern (WindowsForms) tootltip or tooltip control is associated to a single control. But you can use ToolTip control (see example how: ToolTip: Windows Forms .NET) and assign to all controls that recieve mouseover event.
If you're in WPF, the story becomes easier as you have message routing so usually it's enought to have subscription in one place.
Hope this helps.

In a WPF ListView how can I prevent auto scrolling?

I have a WPF ListView which currently scrolls everytime I click on an item which is only partially visible. How can I keep the control from scrolling that item into view (instead simply selecting the partially visible one)? This behavior is very annoying when doing a drag from this control.
Thanks.
Added: I am looking for a solution to keep the control itself from scrolling when contents are clicked that the control believes are not fully visible. Often this is by a few pixels and the scroll is not necessary.
The items scroll into view because the default behavior on list item click is to call BringIntoView(). You can add an event handler for the RequestBringIntoView event and catch it before it bubbles up from the ListViewItems to the ScrollViewer. In your handler, check the bounds of the sender against the visible region and if you decide that you don't need to scroll, set the event's Handled flag to true.
Since I'm currently on the road, I cannot try this, but have you tried playing around with CanContentScroll, and/or wrapping the scrollable content into a Panel, as suggested by the ScrollViewer Overview on MSDN?
In the worst case, you might want to replace the ListView's ItemsPanel by a hacked ScrollViewer with a "fuzz" factor, e.g. by capturing the RequestBringIntoView event.
have you tried this approach?
just as an addon, I don't know how much you know about the subject, but here is a good place to read more about it.
added:
I just found that you can prevent the mouse wheel of scrolling as well.

Categories