在视图面板的网格中自动换行? [英] text wrapping in grid in view panel?

查看:109
本文介绍了在视图面板的网格中自动换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一份调查表.它将在一个选项卡中.我想三列:问题编号,问题,分组框.我将有14个这样的东西,所以所有东西都必须有自己的一行.第2列中的文本有时会足够长,可以换行.我感觉我已经尝试了每种组合,但是我得到的字体要么很大,要么很小.我希望能够调整窗口的大小.我最近所做的任何事情都会使其在垂直方向上调整大小,而在水平方向上没有调整大小.我是个初学者,所以我提前为间隔道歉.

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>

推荐答案

如果要针对14个问题进行此操作,则建议使用数据驱动的解决方案.编写一个Question类,然后将14个Question对象添加到一个集合中,并将该集合与具有某些datatemplate的items控件进行数据绑定.

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>

这篇关于在视图面板的网格中自动换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆