Search icon in the control: http://www.easyicon.net/1183666-Search_icon.html
The search box design process is relatively simple:
1, first define a rectangle as the background
2, then the middle of the textbox input, you can rewrite the template. The prompt label is placed in the template, and you can control the hidden display in the trigger of the template ~
3, Search button-everyone on the Internet next on the line.
UserControl Interface:
<UserControlx:class= "Wpfapplication18.searchcontrol"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"XMLNS:MC= "http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"mc:ignorable= "D"MinHeight= "+"MinWidth= "Max"Background= "Transparent"D:designheight= "+"D:designwidth= "Max"> <Grid> <grid.columndefinitions> <ColumnDefinitionWidth= " the"></ColumnDefinition> <ColumnDefinitionWidth="*"></ColumnDefinition> <ColumnDefinitionWidth= "The "></ColumnDefinition> </grid.columndefinitions> <RectangleGrid.column= "0"Grid.columnspan= "3"Fill= "Lightgray"RadiusX= " the"RadiusY= " the"Opacity= "0.8"></Rectangle> <TextBoxx:name= "Tbxinput"Grid.column= "1"KeyDown= "Tbxinput_onkeydown"> <textbox.template> <ControlTemplateTargetType= "TextBox"> <Grid> <TextBlockx:name= "Uc_tblshow"Text= "Please enter ..."Foreground= "Gray"Opacity= "0.5"VerticalAlignment= "Center"Visibility= "Collapsed"></TextBlock> <TextBoxx:name= "Uc_tbxcontent"Foreground= "Gray"Background= "Transparent"VerticalAlignment= "Center"verticalcontentalignment= "Center"borderthickness= "0"Text="{Binding Elementname=tbxinput,path=text,mode=twoway}"FontSize= "+"></TextBox> </Grid> <controltemplate.triggers> <TriggerSourceName= "Uc_tbxcontent" Property= "Text"Value=""> <SetterTargetName= "Uc_tblshow" Property= "Visibility"Value= "Visible"></Setter> </Trigger> <TriggerSourceName= "Uc_tbxcontent" Property= "IsFocused"Value= "True"> <SetterTargetName= "Uc_tblshow" Property= "Visibility"Value= "Collapsed"></Setter> </Trigger> </controltemplate.triggers> </ControlTemplate> </textbox.template> </TextBox> <Buttonx:name= "Btnsearch"Grid.column= "2"Click= "Btnsearch_onclick"Cursor= "Hand"> <button.template> <ControlTemplateTargetType= "button"> <Grid> <Imagex:name= "Uc_image"Source= "1181298.png"Height= " the"Width= " the"></Image> <ContentPresenter></ContentPresenter> </Grid> <controltemplate.triggers> <Trigger Property= "IsMouseOver"Value= "true"> <SetterTargetName= "Uc_image" Property= "Height"Value= "+"></Setter> <SetterTargetName= "Uc_image" Property= "Width"Value= "+"></Setter> </Trigger> </controltemplate.triggers> </ControlTemplate> </button.template> </Button> </Grid></UserControl>
View Code
UserControl Backstage:
Public Partial classSearchcontrol:usercontrol { PublicSearchControl () {InitializeComponent (); } Public EventEventhandler<searcheventargs>Onsearch; Private voidBtnsearch_onclick (Objectsender, RoutedEventArgs e) {Execcutesearch (); } Private voidTbxinput_onkeydown (Objectsender, KeyEventArgs e) {Execcutesearch (); } Private voidExeccutesearch () {if(onsearch!=NULL) { varargs=NewSearcheventargs (); Args. SearchText=Tbxinput.text; Onsearch ( This, args); } } } Public classSearcheventargs:eventargs { Public stringSearchText {Get;Set; } }
View Code
Just a direct quote,:<wpfapplication18:searchcontrol></wpfapplication18:searchcontrol>.
WPF Custom Search box