C# 网格中的列表框将不会调整大小

C# 网格中的列表框将不会调整大小,c#,xaml,listbox,C#,Xaml,Listbox,这是为Chris W重新更新的。这有完整的代码。我的问题一定更高。我真的很讨厌宽度/高度/边距。将最后一行定义设置为*,删除边距并更改垂直对齐=顶部似乎对我有效 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="300" /> &


这是为Chris W重新更新的。这有完整的代码。我的问题一定更高。我真的很讨厌宽度/高度/边距。

将最后一行定义设置为*,删除边距并更改垂直对齐=顶部似乎对我有效

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Rectangle Fill="#8686EA" Grid.Column="0" />
    <Rectangle Fill="#FFFFE1" Grid.Column="1" />
    <TextBlock x:Name="NickNameBlock" HorizontalAlignment="Left" Margin="10,22,0,0" TextWrapping="Wrap" Text="Nickname" VerticalAlignment="Top"/>
    <TextBox x:Name="NickName" HorizontalAlignment="Left" Margin="84,10,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="109"/>
    <TextBlock x:Name="ChannelBlock" HorizontalAlignment="Left" Margin="10,59,0,0" TextWrapping="Wrap" Text="Channel" VerticalAlignment="Top"/>
    <TextBox x:Name="Channel" HorizontalAlignment="Left" Margin="84,47,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="109"/>
    <Button x:Name="JoinButton" Content="Join" HorizontalAlignment="Left" Margin="198,47,0,0" VerticalAlignment="Top"/>
    <Grid Grid.Column="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="630" />
            <ColumnDefinition Width="200" />
        </Grid.ColumnDefinitions>
        <Rectangle Fill="white" Stroke="Black" StrokeThickness="0" Grid.Column="0" Margin="10,27,0,100" />
        <!--<Rectangle Fill="white" Stroke="Black" StrokeThickness="1" Grid.Column="1" Margin="6,10,71,196" />-->
        <Grid Grid.Column="1" Margin="0,0,0,196">
            <Grid.RowDefinitions>
                <RowDefinition Height="40"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Rectangle Fill="#8686EA" Stroke="Black" StrokeThickness="0" Grid.Row="0" Margin="10,0,0,0" />
            <Rectangle Fill="#CCCCFF" Stroke="Black" StrokeThickness="0" Grid.Row="1" Margin="10,0,0,-5" RenderTransformOrigin="0.505,0.719" Grid.RowSpan="2" />
            <ListBox x:Name="listBox" Grid.Row="2" Margin="10,10,0,0"  VerticalAlignment="Top" VerticalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ListBox.Items>
                    <ListBoxItem Content="Tewl"/>
                    <ListBoxItem Content="Ryu"/>
                    <ListBoxItem Content="Clint"/>
                    <ListBoxItem Content="Bak3r"/>
                    <ListBoxItem Content="sm0kex"/>
                    <ListBoxItem Content="Jack"/>
                    <ListBoxItem Content="Bam"/>
                    <ListBoxItem Content="Jay"/>
                    <ListBoxItem Content="Tewl"/>
                    <ListBoxItem Content="Ryu"/>
                    <ListBoxItem Content="Clint"/>
                    <ListBoxItem Content="Bak3r"/>
                    <ListBoxItem Content="sm0kex"/>
                    <ListBoxItem Content="Jack"/>
                    <ListBoxItem Content="Bam"/>
                    <ListBoxItem Content="Jay"/>
                    <ListBoxItem Content="Tewl"/>
                    <ListBoxItem Content="Ryu"/>
                    <ListBoxItem Content="Clint"/>
                    <ListBoxItem Content="Bak3r"/>
                    <ListBoxItem Content="sm0kex"/>
                    <ListBoxItem Content="Jack"/>
                    <ListBoxItem Content="Bam"/>
                    <ListBoxItem Content="Jay"/>
                </ListBox.Items>
            </ListBox>
        </Grid>
    </Grid>
</Grid>

将最后一行定义设置为*、删除边距并更改垂直对齐=顶部似乎对我很有用

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Rectangle Fill="#8686EA" Grid.Column="0" />
    <Rectangle Fill="#FFFFE1" Grid.Column="1" />
    <TextBlock x:Name="NickNameBlock" HorizontalAlignment="Left" Margin="10,22,0,0" TextWrapping="Wrap" Text="Nickname" VerticalAlignment="Top"/>
    <TextBox x:Name="NickName" HorizontalAlignment="Left" Margin="84,10,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="109"/>
    <TextBlock x:Name="ChannelBlock" HorizontalAlignment="Left" Margin="10,59,0,0" TextWrapping="Wrap" Text="Channel" VerticalAlignment="Top"/>
    <TextBox x:Name="Channel" HorizontalAlignment="Left" Margin="84,47,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="109"/>
    <Button x:Name="JoinButton" Content="Join" HorizontalAlignment="Left" Margin="198,47,0,0" VerticalAlignment="Top"/>
    <Grid Grid.Column="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="630" />
            <ColumnDefinition Width="200" />
        </Grid.ColumnDefinitions>
        <Rectangle Fill="white" Stroke="Black" StrokeThickness="0" Grid.Column="0" Margin="10,27,0,100" />
        <!--<Rectangle Fill="white" Stroke="Black" StrokeThickness="1" Grid.Column="1" Margin="6,10,71,196" />-->
        <Grid Grid.Column="1" Margin="0,0,0,196">
            <Grid.RowDefinitions>
                <RowDefinition Height="40"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Rectangle Fill="#8686EA" Stroke="Black" StrokeThickness="0" Grid.Row="0" Margin="10,0,0,0" />
            <Rectangle Fill="#CCCCFF" Stroke="Black" StrokeThickness="0" Grid.Row="1" Margin="10,0,0,-5" RenderTransformOrigin="0.505,0.719" Grid.RowSpan="2" />
            <ListBox x:Name="listBox" Grid.Row="2" Margin="10,10,0,0"  VerticalAlignment="Top" VerticalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ListBox.Items>
                    <ListBoxItem Content="Tewl"/>
                    <ListBoxItem Content="Ryu"/>
                    <ListBoxItem Content="Clint"/>
                    <ListBoxItem Content="Bak3r"/>
                    <ListBoxItem Content="sm0kex"/>
                    <ListBoxItem Content="Jack"/>
                    <ListBoxItem Content="Bam"/>
                    <ListBoxItem Content="Jay"/>
                    <ListBoxItem Content="Tewl"/>
                    <ListBoxItem Content="Ryu"/>
                    <ListBoxItem Content="Clint"/>
                    <ListBoxItem Content="Bak3r"/>
                    <ListBoxItem Content="sm0kex"/>
                    <ListBoxItem Content="Jack"/>
                    <ListBoxItem Content="Bam"/>
                    <ListBoxItem Content="Jay"/>
                    <ListBoxItem Content="Tewl"/>
                    <ListBoxItem Content="Ryu"/>
                    <ListBoxItem Content="Clint"/>
                    <ListBoxItem Content="Bak3r"/>
                    <ListBoxItem Content="sm0kex"/>
                    <ListBoxItem Content="Jack"/>
                    <ListBoxItem Content="Bam"/>
                    <ListBoxItem Content="Jay"/>
                </ListBox.Items>
            </ListBox>
        </Grid>
    </Grid>
</Grid>

因此,您的边距、行距和不必要的混乱将在将来给您带来更多麻烦。如果你不介意的话,我只是继续写下你在那里的东西,然后把它全部制作好,这样它就可以对你所做的任何调整和事情做出反应。请参阅下面所做的更改,其中包括您的答案。如果是我,我会做更多类似的事情

    <Grid Grid.Column="1" Margin="0,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Rectangle Fill="#8686EA" Stroke="Black" StrokeThickness="0" Grid.Row="0" Margin="10,0,0,0" />
        <Rectangle Fill="#CCCCFF" Stroke="Black" StrokeThickness="0" Grid.Row="1" Margin="10,0,0,0" RenderTransformOrigin="0.505,0.719" />
        <ListBox x:Name="listBox" Grid.Row="2" Margin="10,0,0, 0" VerticalAlignment="Top">
            <ListBox.Items>
                <ListBoxItem Content="Tewl"/>
                <ListBoxItem Content="Ryu"/>
                <ListBoxItem Content="Clint"/>
                <ListBoxItem Content="Bak3r"/>
                <ListBoxItem Content="sm0kex"/>
                <ListBoxItem Content="Jack"/>
                <ListBoxItem Content="Bam"/>
                <ListBoxItem Content="Jay"/>
            </ListBox.Items>
        </ListBox>
    </Grid>

结果:


希望这有帮助,干杯。

因此,您的边距、行距和不必要的杂乱将在将来给您带来更多的麻烦。如果你不介意的话,我只是继续写下你在那里的东西,然后把它全部制作好,这样它就可以对你所做的任何调整和事情做出反应。请参阅下面所做的更改,其中包括您的答案。如果是我,我会做更多类似的事情

    <Grid Grid.Column="1" Margin="0,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Rectangle Fill="#8686EA" Stroke="Black" StrokeThickness="0" Grid.Row="0" Margin="10,0,0,0" />
        <Rectangle Fill="#CCCCFF" Stroke="Black" StrokeThickness="0" Grid.Row="1" Margin="10,0,0,0" RenderTransformOrigin="0.505,0.719" />
        <ListBox x:Name="listBox" Grid.Row="2" Margin="10,0,0, 0" VerticalAlignment="Top">
            <ListBox.Items>
                <ListBoxItem Content="Tewl"/>
                <ListBoxItem Content="Ryu"/>
                <ListBoxItem Content="Clint"/>
                <ListBoxItem Content="Bak3r"/>
                <ListBoxItem Content="sm0kex"/>
                <ListBoxItem Content="Jack"/>
                <ListBoxItem Content="Bam"/>
                <ListBoxItem Content="Jay"/>
            </ListBox.Items>
        </ListBox>
    </Grid>

结果:


希望这能有所帮助,干杯。

首先删除列表框上的硬设置高度和负边距…。然后在最后一行定义中将“自动”更改为“*”。@Chris W.感谢您的支持。。。自从上一篇文章修改后,我做了您告诉我的更改…当窗口未最大化时,我似乎仍然无法获得完整的列表框屏幕[code]设置VerticalContentAlignment=Stretch/VerticalAlignment=Stretch,如果这还不行,那么你的布局结构中会有更高的冲突。它一定是我的上级layout@ChrisW.if您可以再看一次我添加了整个xaml代码。。请先删除列表框上的硬设置高度和负边距。……然后在上一行定义中将“自动”更改为“*”。@Chris W。感谢您的支持。。。自从上一篇文章修改后,我做了您告诉我的更改…当窗口未最大化时,我似乎仍然无法获得完整的列表框屏幕[code]设置VerticalContentAlignment=Stretch/VerticalAlignment=Stretch,如果这还不行,那么你的布局结构中会有更高的冲突。它一定是我的上级layout@ChrisW.if你可以再看一次我添加了整个xaml代码。请一定是我的上级继承人如果你真的从头到尾制作一个IRC应用程序,它一定是我的上级继承人(强调完成的部分)我们可以离线聊天,我可能愿意花一些时间给你一个很酷的UI,以扩展我的投资组合,并以此为例。除了我为那些