The http://www.cnblogs.com/ready4tech/archive/2009/02/13/MouseWheelSupportAddOn.html adds small classes that are supported by the mouse wheel for the Silverlight Control
In fact, there are a lot of articles on the Internet that support the scroll wheel. The principles are the same, through HtmlPage. window. attachEvent ("DOMMouseScroll ",...) to control the ScrollViewer, but many of them are limited to adding scroll wheel support to the ScrollViewer, while the controls such as TextBox and ListBox seem quite different.
Use Reflector to view the implementation of TextBox and ListBox, and find that there is a field inside them as ScrollViewer. As long as you read this field, you should be able to control their scrolling. I tried to use reflection to get their ScrollViewer, but the security mechanism of Silverlight is different from that of the full version of CLR. It does not allow me to get non-public members...
Suddenly... from Reflector, we can see that both TextBox and ListBox use the GetTemplateChild method of the parent class to obtain the ScrollViewer object, while GetTemplateChild is the protected method. Therefore, you only need to create a class that inherits the TextBox or ListBox, then use GetTemplateChild to expose their ScrollViewer!
Namespace Xin. Silverlight. MouseWheelSupport
{
Public class ListBox: System. Windows. Controls. ListBox, IScrollable
{
ScrollViewer sw;
Public ScrollViewer
{
Get
{
If (sw = null)
{
Sw = GetTemplateChild ("ScrollViewer") as ScrollViewer;
}
Return sw;
}
}
}
}
In the code, IScrollable is a small interface written by itself, and declares that the class to implement it must have a ScrollViewer property. In the sample code, this interface is only implemented for TextBox and ListBox. To add scroll wheel support for controls such as GridView, you only need to implement this interface and expose its ScrollViewer object.
After a little bit of code, you only need to executeMouseWheelSupportAddOn. Activate (this. LayoutRoot, true)You can add scroll wheel support to the control that supports scroll wheel for the entire Page.
ActivateThe method can accept ContentControl, Panel, and IScrollable objects. The second parameter specifies whether to add scroll wheel support to the Children of the control.