2014-10-07 51 views
0

我在页面加载事件中将默认值分配给自动完成框。如果我分配了默认值,则下拉菜单将打开并显示分配的值。任何人都可以请帮助如何关闭下拉在自动完成框下在wp7中隐藏自动完成框下拉

回答

0

查找下面XAML代码:

<phone:PhoneApplicationPage 
x:Class="SampleAutoCompleteBox.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
xmlns:local="clr-namespace:SampleAutoCompleteBox" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
SupportedOrientations="Portrait" Orientation="Portrait" 
shell:SystemTray.IsVisible="True" 
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"> 

<phone:PhoneApplicationPage.Resources> 
    <local:SampleWords 
    x:Key="AutoCompletions" /> 
</phone:PhoneApplicationPage.Resources> 

<!--LayoutRoot is the root grid where all page content is placed--> 
<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <!--TitlePanel contains the name of the application and page title--> 
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
     <TextBlock x:Name="ApplicationTitle" Text="Sample Auto Complete Box" Style="{StaticResource PhoneTextNormalStyle}"/> 
     <TextBlock x:Name="PageTitle" Text="Example Page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
    </StackPanel> 

    <!--ContentPanel - place additional content here--> 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
     <toolkit:AutoCompleteBox HorizontalAlignment="Left" Width="450" Grid.Row="0"          
           Name="autoCompleteBox1" VerticalAlignment="Top" TextChanged="autoCompleteBox1_TextChanged"/> 
    </Grid> 
</Grid> 

及以下的源代码的代码。在这里我设置AutoCompleteBoxSelectedItem开始页面,但没有在.xaml和textChanged中设置ItemSource我正在设置它的Item源。

public partial class MainPage : PhoneApplicationPage 
{ 
    private string defaultText; 
    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 
     defaultText = "condimentum"; 

     autoCompleteBox1.SelectedItem = defaultText; 

    } 

    private void autoCompleteBox1_TextChanged(object sender, System.Windows.RoutedEventArgs e) 
    { 
     string searchText = ((AutoCompleteBox)sender).SearchText; 
     if (!String.IsNullOrEmpty(searchText) && !defaultText.Equals(searchText)) 
     { 
      autoCompleteBox1.ItemsSource = SampleWords.AutoCompletions; 
      autoCompleteBox1.TextChanged -= autoCompleteBox1_TextChanged; 
     } 


    } 


} 
+0

我试过了,但自动完成框并未显示默认文本。 – Rev 2014-10-07 13:22:33

+0

我已经创建了一个相同的示例,它为我工作..我已更新完整的xaml并完成C#代码..现在检查是否缺少任何东西。 – 2014-10-08 07:11:15

+0

好的,谢谢Pratik Goyal – Rev 2014-10-08 07:34:52