AutoCompleteBox 异步调用WCF 为什么结果不显示?
<input:AutoCompleteBox x:Name="AutoBox" Height="22" Margin="91,6,0,0" VerticalAlignment="Top" Width="180" RenderTransformOrigin="0.5,1" MinimumPrefixLength="0" MaxDropDownHeight="0" Populating="AutoBox_Populating" HorizontalAlignment="Left">
<input:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</input:AutoCompleteBox.ItemTemplate>
</input:AutoCompleteBox>
private void AutoBox_Populating(object sender, System.Windows.Controls.PopulatingEventArgs e)
{
e.Cancel = true;
src = objMessage.GetAutoStrings(AutoBox.Text);
AutoBox.ItemsSource = list;//list里面读取到string集合了
AutoBox.PopulateComplete();
}
界面输入数据时,数据不会显示出来,不知道哪里出问题了???
[解决办法]
AutoBox_Populating事件需要在构造函数中调用进行数据初始化。
试试:
<UserControl xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input" x:Class="SL3_test1.SilverlightControl23" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:SL3_test1" Width="400" Height="300"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <my:ColorConverter x:Name="cc1"/> </Grid.Resources> <StackPanel> <input:AutoCompleteBox Name="acb1" ValueMemberBinding="{Binding Name}"> <input:AutoCompleteBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" Foreground="{Binding Status,Converter={StaticResource cc1}}"/> </DataTemplate> </input:AutoCompleteBox.ItemTemplate> </input:AutoCompleteBox> </StackPanel> </Grid></UserControl>