轻轻松松为Sliverlight控件或页面添加鼠标滚轮操作
2010-09-16 15:46
330 查看
我们都知道鼠标滚轮的支持只限于浏览器上,但国外的一个高人
Adam Cooper 制作了这几个文件(下载),只要你添加到你的项目中,
立即可以为你的Sliverlight的页面,和页面上的控件,如textBox,ListBox等等,添加鼠标的滚轮支持!
代码如下:
在xaml里:-------------------------------------------------------------------------------------------------
<ScrollViewer x:Name="MyScroller" Width="300" Height="100" Background="AliceBlue">
<TextBlock TextWrapping="Wrap">
一大段文字...
</TextBlock>
</ScrollViewer>
C#代码:---------------------------------------------------------------------------------------------------
using Cooper.Silverlight.Controls;
public Page()
{
InitializeComponent();
ScrollViewerMouseWheelSupport.Initialize(this);
MyScroller.AddMouseWheelSupport();
}
搞定!就是这么简单,仅仅这几行代码而已!
也可以在自己定义的textBox里添加滚轮操作:
public class MyTextBox : TextBox
{
private Grid layoutRoot;
private ScrollViewer scroller;
public MyTextBox()
{
Template = (ControlTemplate)Application.Current.Resources["myTextBox"];
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
layoutRoot = (Grid) GetTemplateChild("layoutRoot");
scroller = (ScrollViewer)GetTemplateChild("scrollViewer");
ScrollViewerMouseWheelSupport.Initialize(layoutRoot);
scroller.AddMouseWheelSupport();
}
}
真的是太方便了!
Adam Cooper 制作了这几个文件(下载),只要你添加到你的项目中,
立即可以为你的Sliverlight的页面,和页面上的控件,如textBox,ListBox等等,添加鼠标的滚轮支持!
代码如下:
在xaml里:-------------------------------------------------------------------------------------------------
<ScrollViewer x:Name="MyScroller" Width="300" Height="100" Background="AliceBlue">
<TextBlock TextWrapping="Wrap">
一大段文字...
</TextBlock>
</ScrollViewer>
C#代码:---------------------------------------------------------------------------------------------------
using Cooper.Silverlight.Controls;
public Page()
{
InitializeComponent();
ScrollViewerMouseWheelSupport.Initialize(this);
MyScroller.AddMouseWheelSupport();
}
搞定!就是这么简单,仅仅这几行代码而已!
也可以在自己定义的textBox里添加滚轮操作:
public class MyTextBox : TextBox
{
private Grid layoutRoot;
private ScrollViewer scroller;
public MyTextBox()
{
Template = (ControlTemplate)Application.Current.Resources["myTextBox"];
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
layoutRoot = (Grid) GetTemplateChild("layoutRoot");
scroller = (ScrollViewer)GetTemplateChild("scrollViewer");
ScrollViewerMouseWheelSupport.Initialize(layoutRoot);
scroller.AddMouseWheelSupport();
}
}
真的是太方便了!
相关文章推荐
- 为Silverlight控件添加鼠标滚轮支持
- 遍历ASP.NET页面上的TextBox控件,并为其添加鼠标事件
- VS2010和IE8是怎样让"Ctrl+鼠标滚轮的上下操作"实现改变字体或页面大小的
- 为Silverlight控件添加鼠标滚轮支持的小类
- 为Silverlight控件添加鼠标滚轮支持的小类
- js实现的鼠标滚轮滚动切换页面效果(类似360默认页面滚动切换效果)
- 页面动态添加用户控件
- 为ASP.NET控件添加常用的JavaScript操作
- 关于页面动态添加控件
- 如何将地图控件添加到 Windows Phone 8 中的页面中
- My Silverlight系列(2)——绝对定位下的控件动态添加操作
- ASP.net 中关于控件Treeview的操作------ 节点查找、删除和添加
- MFC ClistCtrl控件添加右键操作
- Master模板的ASPX页面动态添加控件
- 解决Winform中鼠标滚轮无法操作Panel滚动条的问题
- Qt树形控件QTreeView使用1——节点的添加删除操作
- JSP页面 控制控件显示的JS操作
- 使用jQuery的Scrollify插件实现鼠标滚轮或者手势滑动到页面下一节点部分
- C# 如何用按钮实现鼠标滚轮操作
- 关于页面动态添加控件(转)