聊天框超过大小时自动滚动到最底层

This commit is contained in:
ZouJin 2024-03-13 18:57:48 +08:00
parent ead7115ac9
commit b61b4996f2
3 changed files with 8 additions and 3 deletions

View File

@ -21,10 +21,10 @@
<Label x:Name="LName" Content="虚拟桌宠名字:" Foreground="{DynamicResource PrimaryText}" <Label x:Name="LName" Content="虚拟桌宠名字:" Foreground="{DynamicResource PrimaryText}"
HorizontalAlignment="Left" Padding="0" FontWeight="Bold" Margin="0,0,0,6" FontSize="32" HorizontalAlignment="Left" Padding="0" FontWeight="Bold" Margin="0,0,0,6" FontSize="32"
Background="{x:Null}" /> Background="{x:Null}" />
<ScrollViewer MaxHeight="400"> <ScrollViewer x:Name="sv" MaxHeight="400">
<TextBox x:Name="TText" Text="我说话长这样,这是我说的话巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉" IsReadOnly="True" <TextBox x:Name="TText" Text="我说话长这样,这是我说的话巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉巴拉" IsReadOnly="True"
TextWrapping="WrapWithOverflow" FontSize="24" x:FieldModifier="public" Background="{x:Null}" TextWrapping="WrapWithOverflow" FontSize="24" x:FieldModifier="public" Background="{x:Null}"
BorderBrush="{x:Null}" BorderThickness="0" /> BorderBrush="{x:Null}" BorderThickness="0" SizeChanged="TText_SizeChanged" />
</ScrollViewer> </ScrollViewer>
<Grid x:Name="MessageBoxContent" x:FieldModifier="public"> <Grid x:Name="MessageBoxContent" x:FieldModifier="public">

View File

@ -221,5 +221,10 @@ namespace VPet_Simulator.Core
private void ContextMenu_Opened(object sender, RoutedEventArgs e) => Border_MouseEnter(null, null); private void ContextMenu_Opened(object sender, RoutedEventArgs e) => Border_MouseEnter(null, null);
private void ContextMenu_Closed(object sender, RoutedEventArgs e) => Border_MouseLeave(null, null); private void ContextMenu_Closed(object sender, RoutedEventArgs e) => Border_MouseLeave(null, null);
private void TText_SizeChanged(object sender, SizeChangedEventArgs e)
{
sv.ScrollToEnd();
}
} }
} }

View File

@ -249,12 +249,12 @@ namespace VPet_Simulator.Core
public event Action EventShow; public event Action EventShow;
public void Show() public void Show()
{ {
EventShow?.Invoke();
if (m.UIGrid.Children.IndexOf(this) != m.UIGrid.Children.Count - 1) if (m.UIGrid.Children.IndexOf(this) != m.UIGrid.Children.Count - 1)
{ {
Panel.SetZIndex(this, m.UIGrid.Children.Count); Panel.SetZIndex(this, m.UIGrid.Children.Count);
} }
Visibility = Visibility.Visible; Visibility = Visibility.Visible;
EventShow?.Invoke();
if (CloseTimer.Enabled) if (CloseTimer.Enabled)
onFocus = true; onFocus = true;
else else