使用文本框,对TextBox.TextChanged
做出反应
如果每次更改Text
的{{1}}属性时都要滚动到末尾,建议您切换到TextBlock
,以便可以连接到其{{1 }}使用TextBox
的事件:
TextChanged
使用TextBlock,对System.Windows.Interactivity
做出反应
如果您希望在单击<Window x:Class="WpfApp1.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Width="50" Height="25" Click="Button_Click"></Button>
<ScrollViewer Grid.Row="1" Name="ServerScroll"
VerticalScrollBarVisibility="Auto">
<TextBox Name="serverConsole"
Margin="5"
Background="White"
TextWrapping="Wrap">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<ei:CallMethodAction MethodName="ScrollToEnd" TargetObject="{Binding ElementName=ServerScroll}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</ScrollViewer>
</Grid>
</Window>
时滚动到末尾,则可以使用相同的技术来连接到其Button.Click
事件:
Button
使用ListView,对Click
做出反应
不过,您似乎真的想使用<Window x:Class="WpfApp1.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Width="50" Height="25" Click="Button_Click">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:CallMethodAction MethodName="ScrollToEnd" TargetObject="{Binding ElementName=ServerScroll}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<ScrollViewer Grid.Row="1" Name="ServerScroll"
VerticalScrollBarVisibility="Auto">
<TextBlock Name="serverConsole"
Margin="5"
Background="White"
TextWrapping="Wrap">
</TextBlock>
</ScrollViewer>
</Grid>
</Window>
而不是CollectionChanged
,因为您正在谈论条目和所有内容。您也可以切换到ItemsControl
并连接到其TextBlock
事件:
ListView
在您的视图模型中:
CollectionChanged
本文链接:https://www.f2er.com/3112604.html