视图面板中网格中的文本换行?

发布于 2024-10-24 18:45:27 字数 2865 浏览 4 评论 0原文

我想写一份调查问卷。它将位于一个选项卡中。我想要三列:问题编号、问题、组框。我将有 14 个这样的东西,所以所有东西都必须有自己的行。第 2 列中的文本有时足够长,可以换行。我觉得我已经尝试了所有组合,但我要么得到非常大的字体,要么得到非常小的字体。我希望能够调整窗口大小。无论我最近做了什么,它都会垂直调整大小,但不会水平调整。我是一个初学者,所以我提前为间距表示歉意。

<Grid>
  <Label Name="ADCS" Content="ADCS" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="6" />
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="270*" />
            <ColumnDefinition Width="54*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
            <Viewbox>
            <StackPanel HorizontalAlignment="Left" Name="stackPanel2">
                <Label Name="a1" Content="1." Grid.Column="1" Grid.Row="1"   Margin="6" />
                <Label Name="lblADCS1" Grid.Column="2" Grid.Row="1" Margin="6" />
                <TextBlock 
                        Text="Do you like cheese?" TextWrapping = "WrapWithOverflow">
                </TextBlock>
                <GroupBox Header="ADCS1" Grid.Row="1" Grid.Column="3">
                        <StackPanel Orientation="Horizontal" >
                            <RadioButton Margin ="5" Name="Yes__1" />
                            <RadioButton Margin ="5" Name="No__1" />
                            <RadioButton Margin ="5" Name="Maybe__1" />
                            <RadioButton Margin ="5" Name="Clear__1" />
                        </StackPanel>
                    </GroupBox>
                <Label Name="a2" Content="2." Grid.Column="1" Grid.Row="2" Margin="6" />
                <Label Name="lblADCS2" Grid.Column="2" Grid.Row="2" Margin="6">
                    <TextBlock 
                        Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua?" 
                        TextWrapping = "WrapWithOverflow">
                    </TextBlock>
                </Label>
                <GroupBox Header="ADCS2" Grid.Column="3" Grid.Row="2" >
                    <StackPanel Orientation="Horizontal" >
                        <RadioButton Margin ="5" Name="Yes__2" />
                        <RadioButton Margin ="5" Name="No__2" />
                        <RadioButton Margin ="5" Name="Maybe__2" />
                        <RadioButton Margin ="5" Name="Clear__2" />
                    </StackPanel>
                </GroupBox>
            </StackPanel>
        </Viewbox>
    </Grid>
</Grid>

I want to write a questionnaire. It will be in a tab. I would like three columns: Question Number, Question, Group Box. I will have 14 of these so everything has to have their own row. The text in column 2 will sometimes be long enough to wrap. I feel like I have tried every combination, but I either get really big font or really small font. I'd like to be able to resize the window. Whatever I have done most recently makes it resize vertically, but no horizontally. I am very much a beginner so I apologize in advance for spacing.

<Grid>
  <Label Name="ADCS" Content="ADCS" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="6" />
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="270*" />
            <ColumnDefinition Width="54*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
            <Viewbox>
            <StackPanel HorizontalAlignment="Left" Name="stackPanel2">
                <Label Name="a1" Content="1." Grid.Column="1" Grid.Row="1"   Margin="6" />
                <Label Name="lblADCS1" Grid.Column="2" Grid.Row="1" Margin="6" />
                <TextBlock 
                        Text="Do you like cheese?" TextWrapping = "WrapWithOverflow">
                </TextBlock>
                <GroupBox Header="ADCS1" Grid.Row="1" Grid.Column="3">
                        <StackPanel Orientation="Horizontal" >
                            <RadioButton Margin ="5" Name="Yes__1" />
                            <RadioButton Margin ="5" Name="No__1" />
                            <RadioButton Margin ="5" Name="Maybe__1" />
                            <RadioButton Margin ="5" Name="Clear__1" />
                        </StackPanel>
                    </GroupBox>
                <Label Name="a2" Content="2." Grid.Column="1" Grid.Row="2" Margin="6" />
                <Label Name="lblADCS2" Grid.Column="2" Grid.Row="2" Margin="6">
                    <TextBlock 
                        Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua?" 
                        TextWrapping = "WrapWithOverflow">
                    </TextBlock>
                </Label>
                <GroupBox Header="ADCS2" Grid.Column="3" Grid.Row="2" >
                    <StackPanel Orientation="Horizontal" >
                        <RadioButton Margin ="5" Name="Yes__2" />
                        <RadioButton Margin ="5" Name="No__2" />
                        <RadioButton Margin ="5" Name="Maybe__2" />
                        <RadioButton Margin ="5" Name="Clear__2" />
                    </StackPanel>
                </GroupBox>
            </StackPanel>
        </Viewbox>
    </Grid>
</Grid>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里南柯 2024-10-31 18:45:27

如果您打算回答 14 个问题,我建议您采用数据驱动的解决方案。编写一个 Question 类并将 14 个 Question 对象添加到一个集合中,并使用一些数据模板将集合数据绑定到 itemscontrol。

不管怎样,下面是一个网格,显示了两个带有文本换行的问题。

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Label Grid.Column="0" Grid.Row="0" Content="1" /> <!--Question Number-->
    <TextBlock Grid.Column="1" Grid.Row="0" TextWrapping="WrapWithOverflow" Text="Do you like cheese?" /> <!--Question-->
    <GroupBox Header="ADCS1" Grid.Row="0" Grid.Column="2"> <!--Group Box-->
        <StackPanel Orientation="Horizontal" >
            <RadioButton Content="A" />
            <RadioButton Content="B" />
            <RadioButton Content="C" />
        </StackPanel>
    </GroupBox>
    <Label Grid.Column="0" Grid.Row="1" Content="1" /> <!--Question Number-->
    <TextBlock Grid.Column="1" Grid.Row="1" TextWrapping="WrapWithOverflow" Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua?" /> <!--Question-->
    <GroupBox Header="ADCS1" Grid.Row="1" Grid.Column="2"> <!--Group Box-->
        <StackPanel Orientation="Horizontal" >
            <RadioButton Content="A" />
            <RadioButton Content="B" />
            <RadioButton Content="C" />
        </StackPanel>
    </GroupBox>
</Grid>

If you are going to do that for 14 questions I suggest a data driven solution. Write a Question class and add 14 Question objects to a collection and databind the collection to a itemscontrol with some datatemplate.

Anyway, below is a grid that shows two questions with text wrapping.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Label Grid.Column="0" Grid.Row="0" Content="1" /> <!--Question Number-->
    <TextBlock Grid.Column="1" Grid.Row="0" TextWrapping="WrapWithOverflow" Text="Do you like cheese?" /> <!--Question-->
    <GroupBox Header="ADCS1" Grid.Row="0" Grid.Column="2"> <!--Group Box-->
        <StackPanel Orientation="Horizontal" >
            <RadioButton Content="A" />
            <RadioButton Content="B" />
            <RadioButton Content="C" />
        </StackPanel>
    </GroupBox>
    <Label Grid.Column="0" Grid.Row="1" Content="1" /> <!--Question Number-->
    <TextBlock Grid.Column="1" Grid.Row="1" TextWrapping="WrapWithOverflow" Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua?" /> <!--Question-->
    <GroupBox Header="ADCS1" Grid.Row="1" Grid.Column="2"> <!--Group Box-->
        <StackPanel Orientation="Horizontal" >
            <RadioButton Content="A" />
            <RadioButton Content="B" />
            <RadioButton Content="C" />
        </StackPanel>
    </GroupBox>
</Grid>
橙幽之幻 2024-10-31 18:45:27

我对你的代码做了一些更改:

  • 删除了嵌套的 Viewbox、Grid 和 StackPanel,不知道为什么你需要将它们全部放在一起,
  • 使 StackPanel 拉伸
  • 添加滚动查看器

看看它是否适合你

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Label Grid.Row="0" Name="ADCS" Content="ADCS" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="6" />

    <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
        <StackPanel HorizontalAlignment="Stretch" Name="stackPanel2" >
            <Label Name="a1" Content="1." Margin="6" />
            <Label Name="lblADCS1" Margin="6">
                <TextBlock 
                    Text="Do you like cheese?" TextWrapping = "WrapWithOverflow">
                </TextBlock>
            </Label>
            <GroupBox Header="ADCS1">
                <StackPanel Orientation="Horizontal" >
                    <RadioButton Margin ="5" Name="Yes__1" />
                    <RadioButton Margin ="5" Name="No__1" />
                    <RadioButton Margin ="5" Name="Maybe__1" />
                    <RadioButton Margin ="5" Name="Clear__1" />
                </StackPanel>
            </GroupBox>
            <Label Name="a2" Content="2." Margin="6" />
            <Label Name="lblADCS2" Margin="6">
                <TextBlock 
                            Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua?" 
                            TextWrapping = "WrapWithOverflow">
                </TextBlock>
            </Label>
            <GroupBox Header="ADCS2" >
                <StackPanel Orientation="Horizontal" >
                    <RadioButton Margin ="5" Name="Yes__2" />
                    <RadioButton Margin ="5" Name="No__2" />
                    <RadioButton Margin ="5" Name="Maybe__2" />
                    <RadioButton Margin ="5" Name="Clear__2" />
                </StackPanel>
            </GroupBox>
        </StackPanel>
    </ScrollViewer>
</Grid>

希望这有帮助,问候

I've changed a bit your code:

  • removed nested Viewbox, Grid and StackPanel, not sure why would you need them all together here
  • made the StackPanel stretched
  • added scrollviewer

see if it will work for you

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Label Grid.Row="0" Name="ADCS" Content="ADCS" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="6" />

    <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
        <StackPanel HorizontalAlignment="Stretch" Name="stackPanel2" >
            <Label Name="a1" Content="1." Margin="6" />
            <Label Name="lblADCS1" Margin="6">
                <TextBlock 
                    Text="Do you like cheese?" TextWrapping = "WrapWithOverflow">
                </TextBlock>
            </Label>
            <GroupBox Header="ADCS1">
                <StackPanel Orientation="Horizontal" >
                    <RadioButton Margin ="5" Name="Yes__1" />
                    <RadioButton Margin ="5" Name="No__1" />
                    <RadioButton Margin ="5" Name="Maybe__1" />
                    <RadioButton Margin ="5" Name="Clear__1" />
                </StackPanel>
            </GroupBox>
            <Label Name="a2" Content="2." Margin="6" />
            <Label Name="lblADCS2" Margin="6">
                <TextBlock 
                            Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua?" 
                            TextWrapping = "WrapWithOverflow">
                </TextBlock>
            </Label>
            <GroupBox Header="ADCS2" >
                <StackPanel Orientation="Horizontal" >
                    <RadioButton Margin ="5" Name="Yes__2" />
                    <RadioButton Margin ="5" Name="No__2" />
                    <RadioButton Margin ="5" Name="Maybe__2" />
                    <RadioButton Margin ="5" Name="Clear__2" />
                </StackPanel>
            </GroupBox>
        </StackPanel>
    </ScrollViewer>
</Grid>

hope this helps, regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文