Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
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>
Posted
Updated 29-Jun-16 20:10pm

1 solution

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:
XML
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

WPF Tutorial | Grid Panel[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900