SearchBar 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供 View 搜索框的控件。
[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._SearchBarRenderer))]
public class SearchBar : Xamarin.Forms.InputView, Xamarin.Forms.IElementConfiguration<Xamarin.Forms.SearchBar>, Xamarin.Forms.Internals.IFontElement, Xamarin.Forms.ISearchBarController
type SearchBar = class
inherit InputView
interface IFontElement
interface ISearchBarController
interface IElementConfiguration<SearchBar>
- 继承
- 属性
- 实现
注解
下面的示例演示了基本用法。
public class App : Application
{
Label resultsLabel;
SearchBar searchBar;
public App ()
{
resultsLabel = new Label {
Text = "Result will appear here.",
VerticalOptions = LayoutOptions.FillAndExpand,
FontSize = 25
};
searchBar = new SearchBar {
Placeholder = "Enter search term",
SearchCommand = new Command(() => {resultsLabel.Text = "Result: " + searchBar.Text + " is what you asked for.";})
};
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Start,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
Text = "SearchBar",
FontSize = 50
},
searchBar,
new ScrollView
{
Content = resultsLabel,
VerticalOptions = LayoutOptions.FillAndExpand
}
},
Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5)
}
};
}
// OnStart, OnSleep, and OnResume implementations, & etc.
}

构造函数
| 名称 | 说明 |
|---|---|
| SearchBar() |
创建新的 SearchBar. |
字段
| 名称 | 说明 |
|---|---|
| CancelButtonColorProperty |
CancelButtonColor 属性的后盾存储。 |
| CharacterSpacingProperty |
提供 View 搜索框的控件。 |
| FontAttributesProperty |
FontAttributes 属性的后盾存储。 |
| FontFamilyProperty |
FontFamily 属性的后盾存储。 |
| FontSizeProperty |
FontSize 属性的后盾存储。 |
| HorizontalTextAlignmentProperty |
HorizontalTextAlignment 属性的后备存储。 |
| PlaceholderColorProperty |
PlaceholderColor 属性的后备存储。 |
| PlaceholderProperty |
Placeholder 属性的后备存储。 |
| SearchCommandParameterProperty |
SearchCommandParameter 属性的后备存储。 |
| SearchCommandProperty |
SearchCommand 属性的后备存储。 |
| TextColorProperty |
TextColor 属性的后备存储。 |
| TextProperty |
Text 属性的后备存储。 |
| VerticalTextAlignmentProperty |
提供 View 搜索框的控件。 |
属性
| 名称 | 说明 |
|---|---|
| AnchorX |
获取或设置相对于元素边界的任何转换的中心点的 X 组件。 这是一种可绑定属性。 (继承自 VisualElement) |
| AnchorY |
获取或设置相对于元素边界的任何转换的中心点的 Y 分量。 这是一种可绑定属性。 (继承自 VisualElement) |
| AutomationId |
获取或设置允许自动化框架查找此元素并与其交互的值。 (继承自 Element) |
| Background |
提供 View 搜索框的控件。 (继承自 VisualElement) |
| BackgroundColor |
获取或设置将填充 VisualElement 背景的颜色。 这是一种可绑定属性。 (继承自 VisualElement) |
| Batched |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| Behaviors |
获取与此元素关联的行为列表。 这是一种可绑定属性。 (继承自 VisualElement) |
| BindingContext |
获取或设置一个对象,该对象包含由属于此 BindableObject属性的绑定属性所面向的属性。 (继承自 BindableObject) |
| Bounds |
获取元素的边界。 (继承自 VisualElement) |
| CancelButtonColor |
获取或设置取消按钮的颜色。 |
| CharacterSpacing |
获取或设置一个值,该值指示与设备无关的单位数,这些单位应位于条目显示的文本中的字符之间。 适用于文本和占位符。 (继承自 InputView) |
| class |
提供 View 搜索框的控件。 (继承自 NavigableElement) |
| ClassId |
获取或设置用于标识语义相似元素集合的值。 (继承自 Element) |
| Clip |
提供 View 搜索框的控件。 (继承自 VisualElement) |
| DisableLayout |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| Dispatcher |
提供 View 搜索框的控件。 (继承自 BindableObject) |
| EffectControlProvider |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| Effects |
应用于此项的效果的列表。 (继承自 Element) |
| FlowDirection |
获取或设置布局流方向。 (继承自 VisualElement) |
| FontAttributes |
获取用于指示搜索栏文本的字体是粗体、斜体还是两者皆否的值。 |
| FontFamily |
获取或设置搜索栏文本的字体系列。 |
| FontSize |
获取搜索栏中文本的字体大小。 |
| GestureController |
获取视图的手势控制器。 (继承自 View) |
| GestureRecognizers |
与此视图关联的手势识别器的集合。 (继承自 View) |
| Height |
获取此元素的当前呈现高度。 这是一种只读可绑定属性。 (继承自 VisualElement) |
| HeightRequest |
获取或设置此元素所需的高度替代。 (继承自 VisualElement) |
| HorizontalOptions |
获取或设置 LayoutOptions 定义元素在布局周期中的布局方式。 这是一种可绑定属性。 (继承自 View) |
| HorizontalTextAlignment |
获取或设置水平文本对齐方式。 |
| Id |
获取一个值,该值可用于通过应用程序运行唯一标识元素。 (继承自 Element) |
| InputTransparent |
获取或设置一个值,该值指示是否应在用户交互周期中涉及此元素。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsEnabled |
获取或设置一个值,该值指示是否在用户界面中启用此元素。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsFocused |
获取一个值,该值指示当前是否聚焦此元素。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsInNativeLayout |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| IsNativeStateConsistent |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| IsPlatformEnabled |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| IsReadOnly |
获取或设置一个值,该值指示是否应阻止用户修改文本。 默认值为 |
| IsSpellCheckEnabled |
获取或设置控制是否启用拼写检查的值。 (继承自 InputView) |
| IsTabStop |
获取或设置一个值,该值指示此元素是否包含在选项卡导航中。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsVisible |
获取或设置一个值,该值确定此元素是否应是可视化树的一部分。 这是一种可绑定属性。 (继承自 VisualElement) |
| Keyboard |
获取或设置 InputView 的键盘。 这是一种可绑定属性。 (继承自 InputView) |
| LogicalChildren |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| Margin |
获取或设置视图的边距。 (继承自 View) |
| MaxLength |
获取或设置输入的最大允许长度。 (继承自 InputView) |
| MinimumHeightRequest |
获取或设置一个值,该值覆盖元素在布局期间请求的最小高度。 (继承自 VisualElement) |
| MinimumWidthRequest |
获取或设置一个值,该值覆盖元素在布局期间请求的最小宽度。 (继承自 VisualElement) |
| Navigation |
提供 View 搜索框的控件。 (继承自 NavigableElement) |
| NavigationProxy |
提供 View 搜索框的控件。 (继承自 NavigableElement) |
| Opacity |
获取或设置呈现元素时应用于元素的不透明度值。 这是一种可绑定属性。 (继承自 VisualElement) |
| Parent |
获取或设置元素的父元素。 (继承自 Element) |
| ParentView |
已过时.
获取作为此元素最接近的上级元素的 VisualElement元素。 (继承自 Element) |
| Placeholder |
获取或设置控件为空时显示的文本。 (继承自 InputView) |
| PlaceholderColor |
获取或设置占位符文本的颜色。 (继承自 InputView) |
| Platform |
已过时.
提供 View 搜索框的控件。 (继承自 Element) |
| RealParent |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| Resources |
获取或设置本地资源字典。 (继承自 VisualElement) |
| Rotation |
获取或设置呈现元素时围绕 Z 轴(仿射旋转)的旋转角度(以度为单位)。 (继承自 VisualElement) |
| RotationX |
获取或设置呈现元素时围绕 X 轴(透视旋转)的旋转角度(以度为单位)。 (继承自 VisualElement) |
| RotationY |
获取或设置呈现元素时围绕 Y 轴(透视旋转)的旋转角度(以度为单位)。 (继承自 VisualElement) |
| Scale |
获取或设置应用于元素的比例因子。 (继承自 VisualElement) |
| ScaleX |
获取或设置要应用于 X 方向的缩放值。 (继承自 VisualElement) |
| ScaleY |
获取或设置要应用于 Y 方向的缩放值。 (继承自 VisualElement) |
| SearchCommand |
获取或设置当用户按下“搜索”按钮时运行的命令。 |
| SearchCommandParameter |
获取或设置发送到该参数的参数 SearchCommand。 |
| Style |
提供 View 搜索框的控件。 (继承自 NavigableElement) |
| StyleClass |
提供 View 搜索框的控件。 (继承自 NavigableElement) |
| StyleId |
获取或设置用于唯一地标识元素的用户定义的值。 (继承自 Element) |
| TabIndex |
提供 View 搜索框的控件。 (继承自 VisualElement) |
| Text |
获取或设置输入视图的文本。 这是一种可绑定属性。 (继承自 InputView) |
| TextColor |
获取或设置文本颜色。 (继承自 InputView) |
| TextTransform |
提供 View 搜索框的控件。 (继承自 InputView) |
| TranslationX |
获取或设置元素的 X 转换增量。 (继承自 VisualElement) |
| TranslationY |
获取或设置元素的 Y 转换增量。 (继承自 VisualElement) |
| Triggers |
获取与此元素关联的触发器列表。 这是一种可绑定属性。 (继承自 VisualElement) |
| VerticalOptions |
获取或设置 LayoutOptions 定义元素在布局周期中的布局方式。 这是一种可绑定属性。 (继承自 View) |
| VerticalTextAlignment |
提供 View 搜索框的控件。 |
| Visual |
提供 View 搜索框的控件。 (继承自 VisualElement) |
| Width |
获取此元素的当前呈现宽度。 这是一种只读可绑定属性。 (继承自 VisualElement) |
| WidthRequest |
获取或设置此元素的所需宽度重写。 (继承自 VisualElement) |
| X |
获取此元素的当前 X 位置。 这是一种只读可绑定属性。 (继承自 VisualElement) |
| Y |
获取此元素的当前 Y 位置。 这是一种只读可绑定属性。 (继承自 VisualElement) |
方法
活动
| 名称 | 说明 |
|---|---|
| BatchCommitted |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| BindingContextChanged |
每当 BindingContext 属性更改时引发。 (继承自 BindableObject) |
| ChildAdded |
每当将子元素添加到元素时发生。 (继承自 Element) |
| ChildRemoved |
每当从元素中删除子元素时发生。 (继承自 Element) |
| ChildrenReordered |
重新排序 VisualElement 的子级时发生。 (继承自 VisualElement) |
| DescendantAdded |
每当将子元素添加到元素子树时发生。 (继承自 Element) |
| DescendantRemoved |
每当从元素子树中删除子元素时发生。 (继承自 Element) |
| FocusChangeRequested |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| Focused |
当元素接收焦点时发生。 (继承自 VisualElement) |
| MeasureInvalidated |
当视觉元素的布局失效时引发的事件。 (继承自 VisualElement) |
| PlatformSet |
已过时.
提供 View 搜索框的控件。 (继承自 Element) |
| PropertyChanged |
属性发生更改时引发。 (继承自 BindableObject) |
| PropertyChanging |
当属性即将更改时引发。 (继承自 BindableObject) |
| SearchButtonPressed |
当用户按下“搜索”按钮时引发的事件。 |
| SizeChanged |
当 Width 或 Height 属性更改此元素上的值时发生。 (继承自 VisualElement) |
| TextChanged |
编辑器文本更改时引发的事件。 (继承自 InputView) |
| Unfocused |
当元素失去焦点时发生。 (继承自 VisualElement) |
显式接口实现
| 名称 | 说明 |
|---|---|
| IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) |
供Xamarin内部使用。窗体平台。 (继承自 BindableObject) |
| IElementController.SetValueFromRenderer(BindableProperty, Object) |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| IFontElement.FontSizeDefaultValueCreator() |
供Xamarin内部使用。窗体平台。 |
| IFontElement.OnFontAttributesChanged(FontAttributes, FontAttributes) |
供Xamarin内部使用。窗体平台。 |
| IFontElement.OnFontChanged(Font, Font) |
供Xamarin内部使用。窗体平台。 |
| IFontElement.OnFontFamilyChanged(String, String) |
供Xamarin内部使用。窗体平台。 |
| IFontElement.OnFontSizeChanged(Double, Double) |
供Xamarin内部使用。窗体平台。 |
| IGestureController.CompositeGestureRecognizers |
供Xamarin内部使用。窗体平台。 (继承自 View) |
| INameScope.RegisterName(String, Object) |
仅供内部使用。 (继承自 Element) |
| IVisualElementController.EffectiveFlowDirection |
获取平台上元素的有效视觉流方向,同时考虑区域设置和逻辑流设置。 (继承自 VisualElement) |
| IVisualElementController.InvalidateMeasure(InvalidationTrigger) |
此方法供内部使用。 (继承自 VisualElement) |