我的 ComboBox 项目样式如下(简化):
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="35"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" />
<Path Grid.Column="1" Style={StaticResource StarStyle}/>
</Grid>
结果符合预期。我的列表中的一项如下所示:
alt text http://robbertdam.nl/share/p1.png
但是,当我选择该项目时。它看起来像这样:
alt text http://robbertdam.nl/share/p2.png
我想让星星正确对齐。我错过了什么?
最佳答案
我忘了提及我已经定义了此样式
<Style x:Key="ComboItemsStyle" TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
将此样式分配给我的 ComboBox 可以解决这个问题:
<Style x:Key="ComboStyle" TargetType="{x:Type ComboBox}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
关于c# - ComboBox 项目的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/857492/