格式化AutoCompleteBox DropDown

时间:2014-01-20 18:17:20

标签: wpf autocomplete autocompletebox

这必须非常简单,只是缺少它。我有一个自动完成框,它没有填满整个盒子的空间; Sample view of AutoComplete

黄色框被添加到图像中,而不是实际程序的一部分。添加每行的边框以直观地查看每个行所占用的空间。这是DataTemplate的XML;

<Border Height="Auto" BorderBrush="Black" BorderThickness="1" >
<Grid HorizontalAlignment="Stretch">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="5*"/>
        <ColumnDefinition Width="3*"/>
        <ColumnDefinition Width="2*"/>
    </Grid.ColumnDefinitions>
    <StackPanel Grid.Column="0">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Vertical" Grid.Column="0">
                <TextBlock Text="Description:" Foreground="Gray" Margin="2,0,2,0" />
                <TextBlock Text="Item ID:" Foreground="Gray" Margin="2,0,2,0" />
            </StackPanel>
            <StackPanel Orientation="Vertical" Grid.Column="2">
                <TextBlock Text="{Binding Descrip}" Margin="2,0,2,0" />
                <TextBlock Text="{Binding ItemID}" Margin="2,0,2,0" />
            </StackPanel>
        </Grid>
    </StackPanel>
    <StackPanel Grid.Column="1">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Vertical" Grid.Column="0">
                <TextBlock Text="Department ID:" Foreground="Gray" Margin="2,0,2,0" />
                <TextBlock Text="Class ID:" Foreground="Gray" Margin="2,0,2,0" />
            </StackPanel>
            <StackPanel Orientation="Vertical" Grid.Column="2">
                <TextBlock Text="{Binding DepartmentID}" Margin="2,0,2,0" />
                <TextBlock Text="{Binding ClassID}" Margin="2,0,2,0" />
            </StackPanel>
        </Grid>
    </StackPanel>
    <StackPanel Grid.Column="3" HorizontalAlignment="Right">
        <TextBlock Margin="2,0,0,2" FontSize="16" FontWeight="Bold"  >
            <Run Text="$" />
            <Run Text="{Binding Price}" />
        </TextBlock>
    </StackPanel>
</Grid>

由于

1 个答案:

答案 0 :(得分:0)

感谢@ gomi42,这有效;

<Style  x:Key="autoBoxStyle" TargetType="ListBoxItem">
     <Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>