3

好的,Xaml 是我的弱点之一,所以我真的很感激这方面的一些帮助......我想要实现的是在列表框中添加标题、姓名、姓氏,如下所示:

John Doe 先生 John Doe
女士
Jane Doe 女士

这是我到目前为止的 xaml,结果是名称 title 和 surname 相互重叠:

<DataTemplate>
                <Grid>
                    <TextBlock Text="{Binding Title}"  Width="60" Height="25" Margin="4" HorizontalAlignment="Left" />
                    <TextBlock Text="{Binding FirstName}" Width="60" HorizontalAlignment="Center" />
                    <TextBlock Text="{Binding LastName}" Width="60" HorizontalAlignment="Right" />

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="1*"/>
                    </Grid.ColumnDefinitions>
                </Grid>
            </DataTemplate>
4

3 回答 3

4

在每个TextBlock你需要设置Grid.Column="?"哪里?是 0、1 或 2。

如果您不指定列(或行),元素将默认转到 (0,0)。

于 2012-10-01T13:29:08.940 回答
3

使用. Grid.Column_ TextBlockIE:

<TextBlock Text="{Binding Title}"  Width="60" Height="25" Margin="4" HorizontalAlignment="Left" Grid.Column="0"/> 
<TextBlock Text="{Binding FirstName}" Width="60" HorizontalAlignment="Center" Grid.Column="1" /> 
<TextBlock Text="{Binding LastName}" Width="60" HorizontalAlignment="Right" Grid.Column="2" /> 
于 2012-10-01T13:29:21.050 回答
0

For each element in the grid, if you want them in an explicit Row or Column, you must specify them. To do this you would use Grid.Row="X" or Grid.Column="X". If you leave these off, the default value is 0.

In your case, you would want to do the following.

<DataTemplate>
    <Grid>
        <TextBlock Text="{Binding Title}"  Width="60" Height="25" Margin="4" HorizontalAlignment="Left" Grid.Column="0" />
        <TextBlock Text="{Binding FirstName}" Width="60" HorizontalAlignment="Center" Grid.Column="1" />
        <TextBlock Text="{Binding LastName}" Width="60" HorizontalAlignment="Right" Grid.Column="2" />

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>
    </Grid>
</DataTemplate>
于 2012-10-01T13:30:49.657 回答