积极答复者
我的ListView不会随主窗口的最大化一起变大

问题
-
<Window x:Class="ServerShell.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:local="clr-namespace:ServerShell" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" Closing="Window_Closing"> <StackPanel Orientation="Horizontal" Background="Blue"> <Label x:Name="lable" Content="服务状态" Width="149"/> <ListView x:Name="listView" ItemsSource="{Binding}" Width="642"> <ListView.View> <GridView> <GridViewColumn Header="时间" DisplayMemberBinding="{Binding Time, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"/> <GridViewColumn Header="信息" DisplayMemberBinding="{Binding Message}"/> </GridView> </ListView.View> </ListView> </StackPanel> </Window>
答案
-
你应该用Grid。
<Window x:Class="ServerShell.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:local="clr-namespace:ServerShell" mc:Ignorable="d" Title="加密频道聊天器 服务端" Height="450" Width="800" Closing="Window_Closing"> <Grid Background="Navy"> <Grid.ColumnDefinitions> <ColumnDefinition Width="149"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Label x:Name="lable" Content="服务状态" Foreground="YellowGreen" Width="149"/> <ListView x:Name="listView" Grid.Column="1" ItemsSource="{Binding}"> <ListView.View> <GridView> <GridViewColumn Header="时间" DisplayMemberBinding="{Binding Time, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"/> <GridViewColumn Header="正文" DisplayMemberBinding="{Binding Text}" Width="300"/> </GridView> </ListView.View> </ListView> </Grid> </Window>
- 已建议为答案 Roy LiMicrosoft contingent staff 2019年5月20日 2:29
- 已标记为答案 lihuipeng49 2019年5月28日 1:29
全部回复
-
你好,
你已经给listview设置了宽度,所以他不会自动改变。
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
我不设置宽度的情况如下:
<Window x:Class="ServerShell.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:local="clr-namespace:ServerShell" mc:Ignorable="d" Title="加密频道聊天器 服务端" Height="450" Width="800" Closing="Window_Closing"> <StackPanel Orientation="Horizontal" Background="Navy"> <Label x:Name="lable" Content="服务状态" Foreground="YellowGreen" Width="149"/> <ListView x:Name="listView" ItemsSource="{Binding}"> <ListView.View> <GridView> <GridViewColumn Header="时间" DisplayMemberBinding="{Binding Time, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"/> <GridViewColumn Header="正文" DisplayMemberBinding="{Binding Text}" Width="300"/> </GridView> </ListView.View> </ListView> </StackPanel> </Window>
-
你好,
非UWP 的问题当前论坛不处理。
不过你的问题看起来可以尝试下设置grid 为root control 并且 设置listview所占column 为*.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
你应该用Grid。
<Window x:Class="ServerShell.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:local="clr-namespace:ServerShell" mc:Ignorable="d" Title="加密频道聊天器 服务端" Height="450" Width="800" Closing="Window_Closing"> <Grid Background="Navy"> <Grid.ColumnDefinitions> <ColumnDefinition Width="149"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Label x:Name="lable" Content="服务状态" Foreground="YellowGreen" Width="149"/> <ListView x:Name="listView" Grid.Column="1" ItemsSource="{Binding}"> <ListView.View> <GridView> <GridViewColumn Header="时间" DisplayMemberBinding="{Binding Time, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"/> <GridViewColumn Header="正文" DisplayMemberBinding="{Binding Text}" Width="300"/> </GridView> </ListView.View> </ListView> </Grid> </Window>
- 已建议为答案 Roy LiMicrosoft contingent staff 2019年5月20日 2:29
- 已标记为答案 lihuipeng49 2019年5月28日 1:29