我有一个简单@php
$data = \App\visitor::where('flag',1)->get()
@endphp
的应用程序。来自程序的消息被收集到此日志中并且日志正在滚动,因此用户始终可以看到最后一条消息。在LogView
中,有一个行数很少的网格和两行之间的GridSplitter。日志位于屏幕底部,GridSplitter位于日志之上(用户可以调整日志窗口大小)。
问题出现了:当应用程序启动并且消息被添加到日志窗口时,GridSplitter开始向上移动并且日志窗口开始增长。当用户使用GridSplitter更改日志大小并将消息添加到窗口时,GridSplitter不会移动,并且日志窗口仍然保持其大小。这是显示情况的gif image。
我应该在哪里更改代码,以便ApplicationMainView
从应用程序启动开始保持其大小,用户不必移动GridSplitter?
LogView
所在的ApplicationMainView
代码:
LogView
<Window
x:Class="UI.ApplicationMainView"
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:local="clr-namespace:UI">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<!-- Other controls removed for simplifaction-->
<local:FilesView
Grid.Row="2"
DataContext="{Binding Files}" />
<GridSplitter
Grid.Row="3"
Height="5"
ResizeDirection="Rows"
ResizeBehavior="PreviousAndNext"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
ShowsPreview="True" />
<!-- Here is the log -->
<local:LogView
Grid.Row="4"
DataContext="{Binding Log}" />
</Grid>
</Window>
的代码:
LogView
<UserControl
x:Class="UI.LogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace: UI">
<HeaderedContentControl>
<HeaderedContentControl.Template>
<ControlTemplate
TargetType="HeaderedContentControl">
<DockPanel>
<ContentPresenter
DockPanel.Dock="Top"
ContentSource="Header" />
<ContentPresenter />
</DockPanel>
</ControlTemplate>
</HeaderedContentControl.Template>
<HeaderedContentControl.Header>
<Border
Background="Gray"
CornerRadius="0,20,0,0">
<Label
Content="Log" />
</Border>
</HeaderedContentControl.Header>
<Border
BorderThickness="2,0,2,2"
BorderBrush="Gray">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<DataGrid
x:Name="LogGrid"
Grid.Row="0"
AutoGenerateColumns="False"
CanUserAddRows="False"
IsReadOnly="True"
GridLinesVisibility="None"
MinHeight="50"
ItemsSource="{Binding AllMessages}">
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Time}"
CanUserSort="False"
CanUserReorder="False"
IsReadOnly="True"
Header="Time" />
<DataGridTextColumn
Binding="{Binding Message}"
Width="*"
CanUserSort="False"
CanUserReorder="False"
IsReadOnly="True"
Header="Message" />
</DataGrid.Columns>
</DataGrid>
<DockPanel
Grid.Row="1"
LastChildFill="False">
<Button
Content="Clear"
Command="{Binding ClearLogCommand}" />
<Button
Content="Copy clipboard"
Command="{Binding CopyLogClipboardCommand}" />
</DockPanel>
</Grid>
</Border>
</HeaderedContentControl>
</UserControl>
后面的代码(用于滚动日志):
LogView
答案 0 :(得分:0)
您定义了网格的底行:
<RowDefinition Height="Auto" />
这使LogView增长。
您必须将Height
定义为固定大小
Height="200"
或占屏幕的百分比
Height="*"
或Height="2*"