Watermark in Filter Row of XamDataGrid

This one took some avid Googling and a lucky guess.

To put a Watermark in the Filter Row of a XamDataGrid from Infragistics you need to create a new FilterCellEditorStyle for the XamComboBox which is the editor control in that filter row.

All kudos to Alex Fidanov of Infragistics support who, in this Infragistics Community Thread, “How to show empty string as DisplayText instead of value when value is not found in combo’s ItemsSource”, gave the basic answer.

The basic idea is to swap the Watermark in and out as a complete piece of Content for the XamComboBox, that content replacing the XamCombo’s usual Content.

Here’s WatermarkComboEditorStyle:

Style x:Key="WatermarkComboEditorStyle" TargetType="{x:Type igEdit:XamComboEditor}"
Setter Property="Template"
ControlTemplate TargetType="{x:Type igEdit:XamComboEditor}"
Border x:Name="MainBorder" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
ColumnDefinition Width="*"/
ColumnDefinition Width="Auto"/
Border Grid.Column="0" Margin="1,0,0,0" Padding="{TemplateBinding Padding}"
ContentPresenter x:Name="PART_Content"
Content="{Binding DisplayValue, ConverterParameter='', Mode=OneWay,
RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/
!-- This text box is the actual watermark --
TextBlock x:Name="PART_NullText"
Text="Watermark Text" Visibility="Collapsed" FontStyle="Italic"
Foreground="Gray" FontWeight="Bold" /
ToggleButton x:Name="PART_DropDownButton" ClickMode="Press" Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" Style="{TemplateBinding DropDownButtonStyle}" Visibility="{TemplateBinding DropDownButtonVisibility}" /
Trigger Property="IsEnabled" Value="True"
Setter Property="Visibility" TargetName="PART_DropDownButton" Value="Visible"/
Setter Property="Visibility" Value="Visible" TargetName="PART_NullText"/
Setter Property="Content" Value="" TargetName="PART_Content"/


Once you have created the Style, assign it to FilterCellEditorStyle in the FieldSettings for the Datagrid like so:

Style x:Key="XamDataGridFiltered" TargetType="{x:Type igdp:XamDataGrid}"
BasedOn="{StaticResource XamReadOnlyDataGrid}"
Setter Property="FieldSettings"
igdp:FieldSettings AllowRecordFiltering="True" FilterCellEditorStyle="{StaticResource WatermarkComboEditor}"

Alex is now awarded the title of Slavic Programming Legend. Congrats Alex.


Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: