开发者

wpf combobox padding

This is a simple question

How do you remove the space between the content of a combobox and the border of it. E.g. If the selection of a combobox is "Selection 1" then the "S" is drawn at the very top left of the ComboBox control with no whitespace spacing between it and top left portion of the control.

I did this

<ComboBox Padding="0"/>

Even this:

<ComboBox.ItemContainerStyle>
  <Style TargetType="ComboBoxItem">
    <Setter Property="Padding" Value="0"/>
  </Style>
</ComboBox.ItemContainerStyle>
开发者_如何学Go

The specified ComboBox above is within a ListView GridViewColumn. Maybe that's messing with something.

This doesn't remove the padding. Any ideas?


You can't. At least, not with the default template. You'd have to write your own. The default template includes this:

<DockPanel Margin="2">
    <TextBox .../>
</DockPanel>

That'll be a hard-coded margin. About the best you could do with the default template is use a negative padding to offset the hard-coded margin:

<ComboBox Padding="-2">
    <ComboBoxItem >Selected</ComboBoxItem>
</ComboBox>


In Expression Blend this is trivial:

  1. Right-click the ComboBox and select Edit Control Parts (Template) - Edit A Copy.
  2. Remove the Margin="2" from the beginning of the template.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜