隐藏wp7中的“自动完成”框下拉列表
本文关键字:自动完成 下拉列表 wp7 中的 隐藏 | 更新日期: 2023-09-27 18:25:51
我为页面加载事件中的自动完成框分配了默认值。如果我指定了默认值,则下拉列表将以指定的值打开。有人能帮助如何关闭自动完成框
找到下面的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>
下面是源代码的代码。在这里,我在页面开始时设置AutoCompleteBox
的SelectedItem
,但没有在.xaml中设置ItemSource,在textChanged上,我正在设置其Item source。
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;
}
}
}