如何使XAML文本框可拉伸并防止剪切?

时间:2019-06-21 09:41:23

标签: wpf visual-studio xaml user-interface

我有以下屏幕:

enter image description here

我有以下问题:

  1. 我希望“分析”文本框的大小与窗口大小相同,我使该窗口在水平/垂直窗口以及所有父窗口中均处于拉伸状态,但是当我增大窗口大小时,它仍不会变大(拖动右下角)。

  2. “摘要”文本框被剪裁在右侧,并且我没有任何负边距。

如何解决这些问题?

代码:

<Window x:Class="LAnalyzer.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:LAnalyzer"
        mc:Ignorable="d"
        Title="LAnalyzer" 
        Height="413" Width="729"
        HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <Grid Margin="4,4,4,4"
          HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
          Width="auto" Height="auto">
        <StackPanel
            Orientation="Vertical"
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                Margin="0, 0, 0, 0" 
                Width="auto" Height="auto">
            <Label x:Name="LaFile" 
                Content="Logical Action file (com/int/bin/CC_LA_YY.c)"
                HorizontalAlignment="Left" VerticalAlignment="Top" 
                Margin="0,0,0,0"
                Height="26"  Width="auto" />
            <TextBox x:Name="textBoxLaFile"
                    HorizontalAlignment="Left" VerticalAlignment="Top" 
                    Margin="4,4,4,4" 
                    Height="94" Width="auto" MinWidth="600"
                    TextWrapping="Wrap" 
                    AcceptsReturn="True" 
                    HorizontalScrollBarVisibility="Auto" 
                    VerticalScrollBarVisibility="Auto"/>
            <StackPanel 
                    Orientation="Horizontal" 
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                    Margin="0,0,0,0" 
                    Width="auto" Height="auto">
                <Button x:Name="buttonAnalyze"
                    Content="Analyze" Click="ButtonAnalyze_Click"  
                    HorizontalAlignment="Left" VerticalAlignment="Stretch"
                    Margin="4, 4, 4, 4" 
                    Height="auto" MinHeight="100" Width="100"/>

                <StackPanel 
                    Orientation="Vertical" 
                    Width="auto" Height="auto">
                    <Label x:Name="labelAnalysis"
                        Content="Analysis"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                        Margin="4, 4, 4, 4" 
                        Height="26" Width="auto"/>
                    <TextBox x:Name="textBoxAnalysis" 
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                        HorizontalContentAlignment="Stretch"
                        VerticalContentAlignment="Stretch"
                        Margin="4,4,4,4" 
                        Height="auto" MinHeight="200" Width="auto" MinWidth="400"
                        TextWrapping="Wrap" 
                        IsReadOnly="True" 
                        HorizontalScrollBarVisibility="Auto" 
                        VerticalScrollBarVisibility="Auto"/>
                </StackPanel>

                <StackPanel 
                    Orientation="Vertical" 
                    Margin="0,0,0,0"
                    HorizontalAlignment="Right" VerticalAlignment="Stretch"
                    Width="auto" MinWidth="200" Height="auto">

                    <Label x:Name="labelSummary"
                        Content="Summary"
                        Margin="4,4,4,4" 
                        VerticalAlignment="Top" HorizontalAlignment="Left"
                        Height="auto" Width="auto" />
                    <TextBox  x:Name="textBoxSummary"
                        HorizontalAlignment="Left" VerticalAlignment="Stretch"
                        TextWrapping="Wrap" 
                        Margin="4,4,4,0"
                        Width="auto" MinWidth="200" Height="auto" MinHeight="200"
                        FontFamily="Courier New"
                        VerticalScrollBarVisibility="Auto"/>
                </StackPanel>
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>

1 个答案:

答案 0 :(得分:1)

对于“伸展行为”,您需要网格。

我清理了您的代码。告诉我是否可行。

build.gradle