我正在windows phone 8上开发我的第一个应用程序。在这个应用程序中,我有一个搜索box.For --搜索框--我需要提供背景文本作为搜索城市(作为用户的提示文本)以及框内的搜索符号/搜索按钮,我能知道最好的方法吗?因为我在这个领域非常新。
提前谢谢。
发布于 2014-06-25 07:11:44
尝试这个水印(提示文本)在TextBox和搜索按钮在顶部。
xaml
<Grid x:Name="ContentPanel" Grid.Row="0" Margin="12,0,12,0" Width="440" Height="100">
<TextBox Width="440" Name="txtSearch" Height="153" LostFocus="TextBox_LostFocus" GotFocus="TextBox_GotFocus" Text="This is whatever search..." TextWrapping="Wrap" Foreground="DarkGray" FontSize="18"></TextBox>
<Button x:Name="btnSearch" Click="btnSearch_Click" HorizontalAlignment="Right" Height="70" Margin="0,0,10,0">
<Button.Content>
<Image Source="Images/yoursearchIcon.png"></Image>
</Button.Content>
</Button>
</Grid>代码背后
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
if (txtSearch.Text.Trim() == "")
{
txtSearch.Foreground = new SolidColorBrush(Colors.DarkGray);
txtSearch.Text = "This is whatever search...";
}
}
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
if (txtSearch.Text == "This is whatever search...")
{
txtSearch.Foreground = new SolidColorBrush(Colors.Black);
txtSearch.Text = "";
}
}希望这能有所帮助
发布于 2014-06-25 05:45:49
您也可以使用AutoCompleteBox实现search功能。
查看一下这里
http://www.geekchamp.com/articles/autocompletebox-for-wp7-in-depth
希望能帮上忙!
https://stackoverflow.com/questions/24400996
复制相似问题