none
SL AutoCompleteBox绑定实体问题 RRS feed

  • 常规讨论

  • 如下代码,输入国家后,竟然调不出国家列表,Populating事件中好像获取不了列表.

    xaml如下:
    <input:AutoCompleteBox x:Name="CountryNameAutoCompleteBox" Grid.Row="3" Grid.Column="1" Width="150" MinimumPopulateDelay="200" MinimumPrefixLength="1" HorizontalAlignment="Left" IsTextCompletionEnabled="False" FilterMode="Contains" Tag="CountryCodeValue" SelectionChanged="CountryNameAutoCompleteBox_SelectionChanged" ValueMemberBinding="{Binding Name}">
                                      <input:AutoCompleteBox.ItemTemplate>
                                            <DataTemplate>
                                                <Grid Width="Auto">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="100"></ColumnDefinition>
                                                        <ColumnDefinition></ColumnDefinition>
                                                    </Grid.ColumnDefinitions>
                                                   
                                                    <TextBlock Grid.Column="0" Text="{Binding Name}" HorizontalAlignment="Left" Foreground="Gray"></TextBlock>
                                                    <TextBlock Grid.Column="1" Text="{Binding Code}" HorizontalAlignment="Left" Foreground="Gray"></TextBlock>
                                                </Grid>
                                            </DataTemplate>
                                        </input:AutoCompleteBox.ItemTemplate>
                                    </input:AutoCompleteBox>

    代码如下:

    #region 国家选择
            private void CountryNameAutoCompleteBox_Populating(object sender, PopulatingEventArgs e)
            {
                e.Cancel = true;

                AutoCompleteBox acb = (AutoCompleteBox)sender;
                acb.ItemsSource = null;

                HgCountryContext ctxt = new HgCountryContext();

                EntityQuery<HgCountry> query = ctxt.GetHgCountriesQuery().Take(10);
                LoadOperation<HgCountry> loadop = ctxt.Load(query);
                acb.ItemsSource = loadop.Entities;
                acb.PopulateComplete();
            }


    aaaa
    • 已更改类型 Allen Chen - MSFTModerator 2009年8月6日 6:41 重复帖http://social.msdn.microsoft.com/Forums/en-US/silverlightzhchs/thread/aa957b12-a866-4816-8f23-8ab8deb2e7bf
    2009年8月5日 2:31