2

The ItemTemplate for my ComboBox is like this:

new FuncDataTemplate(
    typeof(object),
    (item, _) => new TextBlock
    {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Text = "Hello",
    })

Yet despite the horizontal alignment being set to stretch, the TextBlock doesn't fill the ComboBoxItem.

1 Answer 1

4

This was because ComboBoxItem.HorizontalContentAlignment is set to Left by default. The issue can be fixed by applying a global style such as:

new Style(s => s.Is<ComboBoxItem>())
{
    Setters =
    {
        new Setter(ComboBoxItem.HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch),
    },
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.