WPF AutoCompleteBox DropDown宽度

时间:2015-10-08 14:49:25

标签: c# wpf xaml

我有以下AutoCompleteBox:

<Controls:AutoCompleteBox x:Name="txtComponent" VerticalAlignment="Center" Height="25" FontFamily="Segoe UI" MinimumPrefixLength="2"
                TextSearch.TextPath="Value" SelectedItem="{Binding Path=Selected, Mode=TwoWay}" IsTextCompletionEnabled="True"
                FontSize="13.333" Grid.Row="0" Grid.Column="1" DropDownClosing="txtComponent_DropDownClosing">
    <Controls:AutoCompleteBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=SiteName}"/>
        </DataTemplate>
    </Controls:AutoCompleteBox.ItemTemplate>
</Controls:AutoCompleteBox>

问题在于建议下拉列表已超出界限。

enter image description here

如何设置DropDown列表的最大宽度?

1 个答案:

答案 0 :(得分:0)

试试这个:

<TextBlock Text="{Binding Path=SiteName}" Width="{Binding ElementName=txtComponent, Path=ActualWidth}"/>

它应该遍历树并将下拉宽度绑定到父宽度。