Robbert Dam
Robbert Dam

Reputation: 4107

Layout of ComboBox items

I have ComboBox item style as follows (simplified):

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="35"/>
    </Grid.ColumnDefinitions>

            <TextBlock Grid.Column="0" />
            <Path Grid.Column="1" Style={StaticResource StarStyle}/>
</Grid>

The result is as expected. An item in my list looks as follows:

alt text http://robbertdam.nl/share/p1.png

Howver, when I select that item. It looks like this:

alt text http://robbertdam.nl/share/p2.png

I want to have the stars right aligned. What am I missing?

Upvotes: 2

Views: 1929

Answers (2)

Robbert Dam
Robbert Dam

Reputation: 4107

I forgot to mention that I've defined this Style

        <Style x:Key="ComboItemsStyle" TargetType="{x:Type ComboBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>

Assigning this style to my ComboBox solves it:

        <Style x:Key="ComboStyle" TargetType="{x:Type ComboBox}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>

Upvotes: 2

Matt Hamilton
Matt Hamilton

Reputation: 204129

Does the "Path" object have an "Align" property? That is, can you force it to align right with this XAML?

<Path Grid.Column="1" Align="Right" Style={StaticResource StarStyle}/>

Edit

No, it doesn't. In that case, I'd suggest embedding the path into a container that can align it. Perhaps:

<DockPanel Grid.Column="1">
    <Path DockPanel.Dock="Right" Style={StaticResource StarStyle}/>
</DockPanel>

Upvotes: 1

Related Questions