8,734
社区成员
发帖
与我相关
我的任务
分享
<Canvas Loaded="StartTimer" x:Name="myCanvas" Background="Black" Height="500" Width=" 500" Margin="142,104,569,184">
</Canvas>
myCanvas.Children.Clear();
for (int j = 0; j < row; j++)//行
{
for (int i = 0; i < col; i++)//列
{
StackPanel myPanel = new StackPanel();
myPanel.Name = Guid.NewGuid().ToString();
myPanel.Height = 100;
myPanel.Width = 100;
double left = 100 * i +i;
double top = 100 * j+j ;
myPanel.SetValue(Canvas.LeftProperty, left);
myPanel.SetValue(Canvas.TopProperty, top);
myPanel.Background = new SolidColorBrush(Colors.Red);
myCanvas.Children.Add(myPanel);
}
}
doubleanimation.From = Canvas.GetTop(ScrollView);
////终点在移动时确定到目标位置路程的一半 即(e.NewValue - e.OldValue)
double d1 = -1 * (this.ScrollView.ActualHeight - this.LayoutRoot.ActualHeight) * e.NewValue;
doubleanimation.To = (-1 * (this.ScrollView.ActualHeight - this.LayoutRoot.ActualHeight) * e.NewValue + doubleanimation.From) / 2;
// 慢动画设置终点
key1.Value = d1;
ScrollBoard.Pause();
ScrollBoard.Begin();
<Canvas Grid.Column="1" Margin="8">
<StackPanel Name="ScrollView" ScrollViewer.VerticalScrollBarVisibility="Auto">
</StackPanel>
</Canvas>
<ScrollBar Grid.Column="2" Width="10" HorizontalAlignment="Right"
Margin="8,0,2,0" d:LayoutOverrides="Width" Background="#FF2B99BE"
Foreground="#FF2B99BE" Orientation="Vertical" Name="Scorller" Cursor="Hand" BorderThickness="0" LargeChange="1" Height="Auto">
</ScrollBar>