有问题正确对齐listbox.datatemplate.grid中的列! [英] Have problem properly align columns from listbox.datatemplate.grid!

查看:99
本文介绍了有问题正确对齐listbox.datatemplate.grid中的列!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,
I'm new with WPF, just start learning, and have minor problem with column alignments.
One binding data "Attachment" is not able to show as column 2, but is under/over column 1, text is mixed with binding data "DateTimeMessage"?!
All other TextBlocks are fine.

Thanks in advance for help

What I have tried:

<code><ListBox x:Name="ListBoxMessages" Height="286" Margin="0,0,-65,0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" FontSize="14">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                            <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0">
                                <Run Text="{Binding Path=FullName}"/>
                                <Run Text="; "/>
                            </TextBlock>
                            <TextBlock Grid.Row="0" Grid.Column="1">
                                <Run Text="{Binding Path=DateTimeMessage, StringFormat=\{0:d.MMM.yyyy HH:mm:ss\}}" />
                                <Run Text="; "/>
                            </TextBlock>
                            <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Path=Attachment}"/>
                            <TextBlock Text="{Binding Path=Message}" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" />
                           </Grid>
                    </DataTemplate>

                </ListBox.ItemTemplate>
            </ListBox></code>

推荐答案

您只定义了两列。第0列的宽度取自该列中控件的大小,第1列占用网格的剩余宽度。



如果你想要三列,那么你必须定义三列:

You have only defined two columns. Column 0 takes its width from the size of the controls in that column, and column 1 takes up the remaining width of the grid.

If you want three columns, then you have to define three columns:
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>



WPF教程网格面板 [ ^ ]


这篇关于有问题正确对齐listbox.datatemplate.grid中的列!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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