0

I want to layout two labels in a fixed width column. One left-aligned and growing to the right, the other directly to the right of it.

When the combined width of the labels is smaller than the available space there should be empty space to the right. This is achieved with this markup:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <TextBlock TextTrimming="CharacterEllipsis" Text="Sample Name" />        
    <Label Content="Text" Foreground="#AAAAAA" Grid.Column="1"/>
</Grid>

First case, left label is short

When the first label is too large, the text is trimmed and the label at the right should not be pushed out of the column. This is achieved with this markup:

<DockPanel LastChildFill="True">
    <Label Content="Text" Foreground="#AAAAAA" DockPanel.Dock="Right" />
    <TextBlock TextTrimming="CharacterEllipsis" Text="A Really Really Long Sample Name" />        
</DockPanel>

Second case, left label is too long

How can I get the same results (the screenshots) without different pieces of Xaml?

4

1 回答 1

0

原来这是我认为我已经尝试过的东西。这为我做到了:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <TextBlock TextTrimming="CharacterEllipsis" Text="Sample Name" />
    <Label Content="Text" Foreground="#AAAAAA" Grid.Column="1" />
</Grid>
于 2013-10-25T20:05:59.847 回答