benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.73k stars 145 forks source link

Style for ComboBox breaks HorizontalContentAlignment #5

Closed nkristek closed 6 years ago

nkristek commented 6 years ago

Setting HorizontalContentAlignment has no effect when the style is active. Adding an empty style like the following fixes the problem, so its definitely caused by the custom style:

<ComboBox ItemsSource="{Binding ComboBoxItems}"
    HorizontalContentAlignment="Stretch">

    <!-- this removes the style but fixes the problem -->
    <ComboBox.Style>
        <Style>

        </Style>
    </ComboBox.Style>

    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!-- Text on the left edge -->
                <TextBlock Grid.Column="0" 
                    Text="Left edge"/>

                <!-- Text on the right edge -->
                <TextBlock Grid.Column="3"
                    Text="Right edge"/>
            </Grid>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
nkristek commented 6 years ago

An issue still persists after f6c107e. The HorizontalContentAligment now applies but with the given example, the content stretches over the full width of the combobox and under the arrow on the right side of the control. Currently, the fix would be:

<ComboBox ItemsSource="{Binding ComboBoxItems}"
    HorizontalContentAlignment="Stretch">

    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="12"/> <!-- this line fixes the problem -->
                </Grid.ColumnDefinitions>

                <!-- Text on the left edge -->
                <TextBlock Grid.Column="0" 
                    Text="Left edge"/>

                <!-- Text on the right edge -->
                <TextBlock Grid.Column="3"
                    Text="Right edge"/>
            </Grid>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

The problem with this fix is, that in the unfolded state this margin is present too

benruehl commented 6 years ago

First fix seemed to work for editable ComboBoxes only, sorry for that. The fix for non-editable ones is out now.