【发布时间】:2014-06-18 02:26:59
【问题描述】:
我这样设置自动完成框:
<StackPanel Orientation="Horizontal">
<StackPanel Width="120">
<Label Content="Address"/>
<Controls:AutoCompleteBox x:Name="AddressBox" MaxDropDownHeight="300" Populating="Address_Populating"/>
</StackPanel>
<StackPanel Width="120" Margin="40, 0, 0, 0">
<Label Content="Port"/>
<TextBox x:Name="PortBox" />
</StackPanel>
<Button x:Name="ConnectButton" Content="Connect" Margin="40, 0, 0, 0" VerticalAlignment="Bottom" Width="80" Height="35" Click="ConnectButton_Clicked"/>
</StackPanel>
但是在下拉窗口中显示的最大项目数只有 3。我确定候选数大于 3。我想增加将在下拉窗口中显示的项目数。
例如,我想显示 15 个候选地址的项目。然后会显示下拉窗口,首先显示 3 个项目。但是我希望它可以先显示5个项目,这意味着应该扩大显示区域。
这个控件的逻辑代码是:
private void Address_Populating(object sender, PopulatingEventArgs e)
{
string dirFile = "../../Config/Address.config";
if (File.Exists(dirFile))
{
var candidateAddress = new List<string>();
string input = null;
using (StreamReader sr = File.OpenText(dirFile))
{
while ((input = sr.ReadLine()) != null)
{
candidateAddress.Add(input);
}
}
AddressBox.ItemsSource = candidateAddress;
AddressBox.PopulateComplete();
}
else
{
System.Windows.MessageBox.Show("Address.config does not exist");
}
}
【问题讨论】:
-
哪个工具包/dll?你应该提供它。
-
工具包的网址是link
-
您能提供您的代码吗?我已经测试过了,一切都是正确的。
-
你的意思是逻辑代码吗?我已经提供了。我可以正确运行这个控件。但是我想扩大显示窗口的面积。
-
不是显示区域的问题。检查candidateAddress的项目和你输入的文字。你能给他们看看吗?
标签: wpf autocompletebox