下面是XAML代码:
<Window
x:Class="scroll.MainWindow"
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:local="clr-namespace:scroll"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="2" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2">
<TabControl Padding="0" TabStripPlacement="Top">
<TabItem Header="Receive">
<ScrollViewer>
<StackPanel Margin="15">
<StackPanel
MaxHeight="40"
Margin="0,4,10,0"
HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Orientation="Horizontal">
<Button
Margin="0,8,18,0"
Background="#349088"
Content="Copy"
FontWeight="ExtraBold"
Foreground="White" />
</StackPanel>
<Label
Margin="0,0,10,0"
Content="Topic"
FontWeight="Bold" />
<TextBox
Margin="0,0,10,0"
FontSize="14"
IsReadOnly="True"
Text="svc/core/state" />
<Label
Margin="0,0,10,0"
Content="Header"
FontWeight="Bold" />
<Expander Margin="0,0,10,0" Header="This is header! Click me to expand the content.">
<Grid>
<TextBox
Name="ReadOnlyHeaderEditor"
Margin="5,2,10,5"
FontFamily="Consolas, Monaco, Menlo,Ubuntu Mono, Monospace"
FontSize="12"
FontWeight="Normal" />
</Grid>
</Expander>
<Label
Margin="0,6,10,0"
Content="Payload"
FontWeight="Bold" />
<Border
Margin="0,0,10,0"
Background="Transparent"
BorderBrush="#C1D2D2"
BorderThickness="0.7"
CornerRadius="4">
<Grid>
<TextBox
VerticalScrollBarVisibility="Auto"
TextWrapping="Wrap"
Text="BLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlahBLahBlahBlah"
Height="300"
Margin="5,2,10,5"
FontFamily="Consolas, Monaco, Menlo,Ubuntu Mono, Monospace"
FontSize="12"
FontWeight="Normal" />
</Grid>
</Border>
<Label
Margin="0,6,10,0"
Content="History of received messages"
FontWeight="Bold" />
</StackPanel>
</ScrollViewer>
</TabItem>
</TabControl>
</DockPanel>
</Grid>
</Grid>
</Window>
我想要的是不允许在一个有很多文本的文本框中滚动,直到一个人将光标放置在文本框中一定的时间。如果光标没有在文本框中设置,我想滚动整个网格,我怎么能做到这一点呢?
我试着做以下事情:尝试处理TextBox的GotFocus和LostFocus以替代光标(可能也是MouseEnter和MouseLeave)。启动计时器。对于滚动传递,尝试处理PreviewMouseWheel并设置e.相应地处理。但我认为这不是正确的方法
1条答案
按热度按时间6ju8rftf1#
你只要取消移动:在ScrollViewer上添加事件
ScrollViewer_ScrollChanged