Class SearchableDataGrid
A searchable datagrid used in the ItemPicker It provides text searching in columns and an optional header.
Inheritance
Implements
Namespace: Sartorius.SAF.Presentation.Controls
Assembly: Sartorius.SAF.Presentation.Controls.dll
Syntax
public class SearchableDataGrid : DataGrid, IAnimatable, ISupportInitialize, IFrameworkInputElement, IInputElement, IQueryAmbient, IContainItemStorage, IAddChild
Remarks
If ColumnDescriptors are not set they will be automatically extracted from the data grids columns. Only DataGridTextColumns with a binding to a property and a set HeaderStringFormat or Header of type string can be automatically extracted. You can set ColumnDescriptors to a ColumnDescriptorCollection containing descriptors for all searchable data members to customize searchable data members other text display in the SearchBox dropdown and watermark.
Examples
The following example shows how to set the ColumnDescriptors in markup.
<SAF:SearchableDataGrid ItemsSource="{Binding Cultures}"
AutoGenerateColumns="False"
SelectionMode="Single"
EmptyTitle="No Items Available"
EmptyFilteredTitle="Items Filtered"
EmptyFilteredMessage="Change or reset the filter to show items">
<DataGrid.Columns>
<DataGridTextColumn Width="170" Header="Display Name" Binding="{Binding DisplayName}" />
<DataGridTextColumn Width="170" Header="English Name" Binding="{Binding EnglishName}" />
<DataGridTextColumn Width="170" Header="Native Name" Binding="{Binding NativeName}" />
<DataGridTextColumn Width="100" Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn Width="100" Header="ISO 639-2" Binding="{Binding ThreeLetterISOLanguageName}" />
</DataGrid.Columns>
<SAF:SearchableDataGrid.ColumnDescriptors>
<SAF:ColumnDescriptorCollection>
<SAF:ColumnDescriptor Header="Display Name" MemberName="DisplayName" />
<SAF:ColumnDescriptor Header="English Name" MemberName="EnglishName" />
<SAF:ColumnDescriptor Header="Native Name" MemberName="NativeName" />
<SAF:ColumnDescriptor Header="Name" MemberName="Name" />
<SAF:ColumnDescriptor Header="ISO 639-2" MemberName="ThreeLetterISOLanguageName" />
</SAF:ColumnDescriptorCollection>
</SAF:SearchableDataGrid.ColumnDescriptors>
</SAF:SearchableDataGrid>
The following example shows how to set the ColumnDescriptors in markup and have the search box display different texts in the dropdown and the text box watermark.
<SAF:SearchableDataGrid ItemsSource="{Binding Cultures}"
AutoGenerateColumns="False"
SelectionMode="Single"
EmptyTitle="No Items Available"
EmptyFilteredTitle="Items Filtered"
EmptyFilteredMessage="Change or reset the filter to show items">
<DataGrid.Columns>
<DataGridTextColumn Width="170" Header="Display Name" Binding="{Binding DisplayName}" />
<DataGridTextColumn Width="170" Header="English Name" Binding="{Binding EnglishName}" />
<DataGridTextColumn Width="170" Header="Native Name" Binding="{Binding NativeName}" />
<DataGridTextColumn Width="100" Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn Width="100" Header="ISO 639-2" Binding="{Binding ThreeLetterISOLanguageName}" />
</DataGrid.Columns>
<SAF:SearchableDataGrid.ColumnDescriptors>
<SAF:ColumnDescriptorCollection>
<!-- This will display 'Display Name' in the search box drop down and 'Search in the display names' in the search box watermark while this entry is selected. -->
<SAF:ColumnDescriptor Header="Display Name" Watermark="the display names" MemberName="DisplayName" />
<SAF:ColumnDescriptor Header="English Name" Watermark="the english names" MemberName="EnglishName" />
<SAF:ColumnDescriptor Header="Native Name" Watermark="the native names" MemberName="NativeName" />
<SAF:ColumnDescriptor Header="Name" Watermark="the names" MemberName="Name" />
<SAF:ColumnDescriptor Header="ISO 639-2" Watermark="the three letter ISO codes (ISO 639-2)"
MemberName="ThreeLetterISOLanguageName" />
</SAF:ColumnDescriptorCollection>
</SAF:SearchableDataGrid.ColumnDescriptors>
</SAF:SearchableDataGrid>
Fields
View SourceColumnDescriptorsProperty
Identifies the DependencyProperty for ColumnDescriptors.
Declaration
public static readonly DependencyProperty ColumnDescriptorsProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
EmptyFilteredMessageProperty
Identifies the DependencyProperty for EmptyFilteredMessage.
Declaration
public static readonly DependencyProperty EmptyFilteredMessageProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
EmptyFilteredTitleProperty
Identifies the DependencyProperty for EmptyFilteredMessage.
Declaration
public static readonly DependencyProperty EmptyFilteredTitleProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
EmptyMessageProperty
Identifies the DependencyProperty for EmptyMessage.
Declaration
public static readonly DependencyProperty EmptyMessageProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
EmptyTitleProperty
Identifies the DependencyProperty for EmptyTitle.
Declaration
public static readonly DependencyProperty EmptyTitleProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
HeaderProperty
Identifies the DependencyProperty for Header.
Declaration
public static readonly DependencyProperty HeaderProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
HeaderTemplateProperty
Identifies the DependencyProperty for HeaderTemplate.
Declaration
public static readonly DependencyProperty HeaderTemplateProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
IsFilteringProperty
Identifies the DependencyProperty for IsFiltering.
Declaration
public static readonly DependencyProperty IsFilteringProperty
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 ColumnDescriptors.
Declaration
public static readonly DependencyProperty SelectedSearchScopeProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
Properties
View SourceColumnDescriptors
Gets or sets the column descriptors.
Declaration
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Can be used as dependency property in Xaml.")]
public ColumnDescriptorCollection ColumnDescriptors { get; set; }
Property Value
| Type | Description |
|---|---|
| ColumnDescriptorCollection | The column descriptors. |
EmptyFilteredMessage
Gets or sets the message that is shown when the content has been filtered away.
Declaration
public string EmptyFilteredMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The message that is shown when the content has been filtered away. |
EmptyFilteredTitle
Gets or sets the title of the message that is shown when the content has been filtered away.
Declaration
public string EmptyFilteredTitle { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The title of the message that is shown when the content has been filtered away. |
EmptyMessage
Gets or sets the the message shown when the grid is empty.
Declaration
public string EmptyMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The the message shown when the grid is empty. |
EmptyTitle
Gets or sets the title of the message shown when the grid is empty.
Declaration
public string EmptyTitle { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The title of the message shown when the grid is empty. |
Header
Gets or sets the header.
Declaration
public object Header { get; set; }
Property Value
| Type | Description |
|---|---|
| object |
HeaderTemplate
Gets or sets the header template.
Declaration
public DataTemplate HeaderTemplate { get; set; }
Property Value
| Type | Description |
|---|---|
| DataTemplate |
IsFiltering
Gets a value indicating whether the dataGrid is currently filtering.
Declaration
public bool IsFiltering { get; }
Property Value
| Type | Description |
|---|---|
| bool | A value indicating whether the dataGrid is currently filtering. |
SearchScopes
Gets or sets the search scopes.
Declaration
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Can be used as dependency property in Xaml.")]
public ColumnDescriptorCollection SearchScopes { get; set; }
Property Value
| Type | Description |
|---|---|
| ColumnDescriptorCollection | The search scopes. |
SearchText
Gets or sets the search string.
Declaration
public string SearchText { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The search string. |
SelectedSearchScope
Gets or sets the current search scope.
Declaration
public object SelectedSearchScope { get; set; }
Property Value
| Type | Description |
|---|---|
| object | The current search scope. |
Methods
View SourceOnApplyTemplate()
applies the template for the DataGrid
Declaration
public override void OnApplyTemplate()
Overrides
View SourceOnItemsSourceChanged(IEnumerable, IEnumerable)
Invoked when the ItemsSource property changes.
Declaration
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | oldValue | The old source. |
| IEnumerable | newValue | The new source. |
Overrides
View SourceOnSelectionChanged(SelectionChangedEventArgs)
Invoked when the selection changes.
Declaration
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| SelectionChangedEventArgs | e | The data for the event. |