1)前台代码
<UserControl x:Class="SilverlightApplication54.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/Expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWIDth="400"> <GrID x:name="LayoutRoot" Background="White"> <GrID.RowDeFinitions> <RowDeFinition Height="50"></RowDeFinition> <RowDeFinition Height="*"></RowDeFinition> </GrID.RowDeFinitions> <button name="Testbutton" WIDth="200" Height="24" Content="Add" GrID.Row="0"></button> <ScrollVIEwer name="TestScrollVIEwer" GrID.Row="1"> <StackPanel name="TestStackPanel" OrIEntation="Vertical"> </StackPanel> </ScrollVIEwer> </GrID></UserControl>
2)后台代码
using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;namespace SilverlightApplication54{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); Testbutton.Click += new RoutedEventHandler(Testbutton_Click); this.MouseWheel += new MouseWheelEventHandler(MainPage_MouseWheel); } /// <summary> /// 当鼠标滚轮时,ScrollVIEwer的滚动条就能就能上下移动了。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> voID MainPage_MouseWheel(object sender,MouseWheelEventArgs e) { ScrollVIEwer vIEwer = TestScrollVIEwer; if (vIEwer == null) return; double num = Math.Abs((int)(e.Delta / 2)); double offset = 0.0; if (e.Delta > 0) { offset = Math.Max((double)0.0,(double)(vIEwer.VerticalOffset - num)); } else { offset = Math.Min(vIEwer.ScrollableHeight,vIEwer.VerticalOffset + num); } if (offset != vIEwer.VerticalOffset) { vIEwer.ScrollToVerticalOffset(offset); e.Handled = true; } } voID Testbutton_Click(object sender,RoutedEventArgs e) { //添加TextBox TextBox textBox = new TextBox(); textBox.WIDth = 200; textBox.Height = 100; TestStackPanel.Children.Add(textBox); } }}总结
以上是内存溢出为你收集整理的silverlight给ScrollViewer滚动条添加响应鼠标滚轮全部内容,希望文章能够帮你解决silverlight给ScrollViewer滚动条添加响应鼠标滚轮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)