c# - ComboBox 项目的布局

标签 c# .net wpf xaml

我的 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/

相关文章:

wpf - 密码框上的样式触发器

c# - 卡住 DataGrid 行

c# - "App.Current.myProperty"不起作用,但 "((app)Application.Current).myProperty"起作用

c# - 如何获取 GridView 上 DataSet.DataTable 的总计?

c# - 如何进行批量插入——Linq to Entities

c# - 当程序集在 'C:\Windows\System32' 内时,我得到 'Unable to find a version of the runtime to run this application'

WPF 样式继承

c# - 从一个窗口访问另一个窗口中的变量值

c# new thread from timer handle 问题

c# - 解析 HTTP JSON 响应 - C#