8,757
社区成员
发帖
与我相关
我的任务
分享
private void Grid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
Grid view = sender as Grid;
switch (view.Name)
{
case "Grid1":
Lable1.Background = Brushes.Gray;
Lable2.Background = Brushes.White;
Lable3.Background = Brushes.White;
Lable4.Background = Brushes.White;
break;
case "Grid2":
Lable2.Background = Brushes.Gray;
Lable1.Background = Brushes.White;
Lable3.Background = Brushes.White;
Lable4.Background = Brushes.White;
break;
case "Grid3":
Lable3.Background = Brushes.Gray;
Lable1.Background = Brushes.White;
Lable2.Background = Brushes.White;
Lable4.Background = Brushes.White;
break;
case "Grid4":
Lable4.Background = Brushes.Gray;
Lable1.Background = Brushes.White;
Lable2.Background = Brushes.White;
Lable3.Background = Brushes.White;
break;
default:
break;
}
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
eventArg.RoutedEvent = UIElement.MouseWheelEvent;
eventArg.Source = sender;
view.RaiseEvent(eventArg);
}
private void Label_MouseDown1(object sender, MouseButtonEventArgs e)
{
Lable1.Background = Brushes.Gray;
Lable2.Background = Brushes.White;
Lable3.Background = Brushes.White;
Lable4.Background = Brushes.White;
scroll.ScrollToVerticalOffset(0);
}
private void Label_MouseDown2(object sender, MouseButtonEventArgs e)
{
Lable2.Background = Brushes.Gray;
Lable1.Background = Brushes.White;
Lable3.Background = Brushes.White;
Lable4.Background = Brushes.White;
scroll.ScrollToVerticalOffset(300);
}
private void Label_MouseDown3(object sender, MouseButtonEventArgs e)
{
Lable3.Background = Brushes.Gray;
Lable1.Background = Brushes.White;
Lable2.Background = Brushes.White;
Lable4.Background = Brushes.White;
scroll.ScrollToVerticalOffset(600);
}
private void Label_MouseDown4(object sender, MouseButtonEventArgs e)
{
Lable4.Background = Brushes.Gray;
Lable1.Background = Brushes.White;
Lable2.Background = Brushes.White;
Lable3.Background = Brushes.White;
scroll.ScrollToVerticalOffset(900);
}
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<StackPanel>
<Label
x:Name="Lable1"
Height="30"
VerticalAlignment="Center"
Content="第一项"
MouseDown="Label_MouseDown1" />
<Label
x:Name="Lable2"
Height="30"
VerticalAlignment="Center"
Content="第二项"
MouseDown="Label_MouseDown2" />
<Label
x:Name="Lable3"
Height="30"
VerticalAlignment="Center"
Content="第三项"
MouseDown="Label_MouseDown3" />
<Label
x:Name="Lable4"
Height="30"
VerticalAlignment="Center"
Content="第四项"
MouseDown="Label_MouseDown4" />
</StackPanel>
<Label VerticalAlignment="Bottom" Content="{Binding ElementName=scroll,Path=VerticalOffset}"/>
</Grid>
<ScrollViewer Grid.Column="1" x:Name="scroll">
<StackPanel Orientation="Vertical">
<Grid
x:Name="Grid1"
Height="300"
Background="Red"
PreviewMouseWheel="Grid_PreviewMouseWheel">
<Label Content="111" />
</Grid>
<Grid
x:Name="Grid2"
Height="300"
Background="Azure"
PreviewMouseWheel="Grid_PreviewMouseWheel">
<Label Content="222" />
</Grid>
<Grid
x:Name="Grid3"
Height="300"
Background="DarkBlue"
PreviewMouseWheel="Grid_PreviewMouseWheel">
<Label Content="333" />
</Grid>
<Grid
x:Name="Grid4"
Height="300"
Background="Violet"
PreviewMouseWheel="Grid_PreviewMouseWheel">
<Label Content="444" />
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
做的一个简单的,看看行不行