Class SearchBox
A box providing a dropdown for search scopes and an search text.
Inheritance
Namespace: Sartorius.SAF.Presentation.Controls
Assembly: Sartorius.SAF.Presentation.Controls.dll
Syntax
[TemplatePart(Name = "PART_Text", Type = typeof(TextBox))]
[SuppressMessage("ReSharper", "LocalizableElement")]
public class SearchBox : Control, IAnimatable, ISupportInitialize, IFrameworkInputElement, IInputElement, IQueryAmbient
Remarks
You can use UpdateSourceTrigger to define how changes to SearchText should be triggered. The default is UpdateSourceTrigger. This means changes are triggered as the user types. This behaviour corresponds to a live search showing results as the user types. The trigger of the changes are delayed by UpdateDelay in this case. UpdateDelay is ignored on all other cases. Setting the UpdateSourceTrigger to explicit, means that the SearchText is updated when pressing the Return key.
You can define different search scopes that can be selected by the user with a dropdown.
By default the Reset button of the control will only be visible when the SearchText is filled. The visibility can be explicitly set with IsResetButtonVisible.
If IsResetButtonVisible is set to null. The property will reflect the current state of the reset button as it is automatically shown and hidden by the control.
Examples
The following example binds to a simple viewmodel class that provides search scopes as a list of strings. The strings will be shown in the drop down. The watermark in the searchbox will show the current selected search scope formated by WatermarkFormat.
<controls:SearchBox SearchText="{Binding SearchText}"
SearchScopes="{Binding SearchScopes}"
WatermarkFormat="Search in {0}"
SelectedSearchScope="{Binding SelectedSearchScope}" />
The viewmodel for this example looks like this:
The following example binds to a simple viewmodel class that provides search scopes as a list of objects. The Caption-property of these search scope objects is used as display text in the dropdown and in the watermark of the search box.
<controls:SearchBox SearchText="{Binding SearchText}"
SearchScopes="{Binding SearchScopes}"
WatermarkFormat="Search in {0}"
SearchScopeDisplayMemberPath="Caption"
SelectedSearchScope="{Binding SelectedSearchScope}" />
The viewmodel for this example looks like this:
The following example additionally uses the Reset event to execute some additional action when the user clicks the reset button. The reset button will be always visible.
<controls:SearchBox SearchText="{Binding SearchText}"
SearchScopes="{Binding SearchScopes}"
SearchScopeDisplayMemberPath="Caption"
SelectedSearchScope="{Binding SelectedSearchScope}"
IsResetButtonVisible="True">
<controls:Interaction.Pipes>
<controls:EventPipe EventName="Reset"
Command="{Binding ResetCommand}" />
</controls:Interaction.Pipes>
</controls:SearchBox>
Constructors
View SourceSearchBox()
Initializes a new instance of the SearchBox class.
Declaration
public SearchBox()
Fields
View SourceIsResetButtonVisibleProperty
Identifies the DependencyProperty for IsResetButtonVisible.
Declaration
public static readonly DependencyProperty IsResetButtonVisibleProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
KeyDownCommandProperty
Identifies the DependencyProperty for KeyDownCommand.
Declaration
public static readonly DependencyProperty KeyDownCommandProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
KeyDownCommandPropertyKey
Identifies the DependencyPropertyKey for KeyDownCommand.
Declaration
protected static readonly DependencyPropertyKey KeyDownCommandPropertyKey
Field Value
| Type | Description |
|---|---|
| DependencyPropertyKey |
ResetCommandProperty
Identifies the DependencyProperty for ResetCommand.
Declaration
public static readonly DependencyProperty ResetCommandProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
ResetEvent
Identifies the RoutedEvent for Reset.
Declaration
public static readonly RoutedEvent ResetEvent
Field Value
| Type | Description |
|---|---|
| RoutedEvent |
SearchDisabledTextProperty
Identifies the DependencyProperty for SearchDisabledText.
Declaration
public static readonly DependencyProperty SearchDisabledTextProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
SearchScopeDisplayMemberPathProperty
Identifies the DependencyProperty for SearchScopeDisplayMemberPath.
Declaration
public static readonly DependencyProperty SearchScopeDisplayMemberPathProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
SearchScopeWatermarkDisplayMemberPathProperty
Identifies the DependencyProperty for SearchScopeWatermarkDisplayMemberPath.
Declaration
public static readonly DependencyProperty SearchScopeWatermarkDisplayMemberPathProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
SearchScopesProperty
Identifies the DependencyProperty for SearchScopes.
Declaration
public static readonly DependencyProperty SearchScopesProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
SearchTextProperty
Identifies the DependencyProperty for SearchText.
Declaration
public static readonly DependencyProperty SearchTextProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
SelectedSearchScopeProperty
Identifies the DependencyProperty for SelectedSearchScope.
Declaration
public static readonly DependencyProperty SelectedSearchScopeProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
UpdateDelayProperty
Identifies the DependencyProperty for UpdateDelay.
Declaration
public static readonly DependencyProperty UpdateDelayProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
UpdateSourceTriggerProperty
Identifies the DependencyProperty for UpdateSourceTrigger.
Declaration
public static readonly DependencyProperty UpdateSourceTriggerProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
WatermarkFormatProperty
Identifies the DependencyProperty for SelectedSearchScope.
Declaration
public static readonly DependencyProperty WatermarkFormatProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
WatermarkProperty
Identifies the DependencyProperty for Watermark.
Declaration
public static readonly DependencyProperty WatermarkProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
Properties
View SourceIsResetButtonVisible
Gets or sets a value indicating wheter the Reset Button should be visible.
Declaration
public bool? IsResetButtonVisible { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
|
KeyDownCommand
Gets the Command that should be executed when a key is pressed down in the search box.
Declaration
public ICommand KeyDownCommand { get; protected set; }
Property Value
| Type | Description |
|---|---|
| ICommand |
ResetCommand
Gets the reset command.
Declaration
public ICommand ResetCommand { get; }
Property Value
| Type | Description |
|---|---|
| ICommand | The reset command. |
SearchDisabledText
Gets or sets the text that is shown if IsEnabled is false.
Declaration
public string SearchDisabledText { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The text that is shown if IsEnabled is |
SearchScopeDisplayMemberPath
Gets or sets the display member path for the search scopes.
Declaration
public string SearchScopeDisplayMemberPath { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The display member path. |
SearchScopeWatermarkDisplayMemberPath
Gets or sets the member path used to display in the text box watermark.
Declaration
public string SearchScopeWatermarkDisplayMemberPath { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The member path used to display in the text box watermark. |
SearchScopes
Gets or sets the available search scopes.
Declaration
public IEnumerable SearchScopes { get; set; }
Property Value
| Type | Description |
|---|---|
| IEnumerable | The available search scopes. |
SearchText
Gets or sets the search text.
Declaration
public string SearchText { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The search text. |
SelectedSearchScope
Gets or sets the selected search scope.
Declaration
public object SelectedSearchScope { get; set; }
Property Value
| Type | Description |
|---|---|
| object | The selected search scope. |
UpdateDelay
Gets or sets the delay in milliseconds used when UpdateSourceTrigger is PropertyChanged.
Declaration
public int UpdateDelay { get; set; }
Property Value
| Type | Description |
|---|---|
| int | The delay used when UpdateSourceTrigger is PropertyChanged. |
Remarks
The default is 200 ms.
UpdateSourceTrigger
Gets or sets the UpdateSourceTrigger for the SearchText binding.
Declaration
public UpdateSourceTrigger UpdateSourceTrigger { get; set; }
Property Value
| Type | Description |
|---|---|
| UpdateSourceTrigger |
Remarks
The default is PropertyChanged. Which means an update of SearchText as the user types (delayed by UpdateDelay). When this is set to Explicit the SearchText is updated when the user presses Return. When set to LostFocus the SearchText is updated when the search box looses focus.
Watermark
Gets the watermark.
Declaration
public string Watermark { get; }
Property Value
| Type | Description |
|---|---|
| string | The watermark. |
WatermarkFormat
Gets or sets the watermark format.
Declaration
public string WatermarkFormat { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The watermark format. |
Remarks
This format defines how the watermark should be displayed for a selected item. The default is '{0}'. But you can use something like 'Search in {0}'.
Methods
View SourceOnApplyTemplate()
When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate().
Declaration
public override void OnApplyTemplate()
Overrides
Events
View SourceReset
Occurs when reset is clicked.
Declaration
public event RoutedEventHandler Reset
Event Type
| Type | Description |
|---|---|
| RoutedEventHandler |