Expression Binding
Last updated
Last updated
In this example we hide the xDataPanel based on the expression binding. We assume that the xDataPanel has the "DataSourcePath" set to "dsArt.art".
XAML initially:
<tl:xDataPanel x:Name="dpArt" DataSourcePath="dsArt.art" x:TypeArguments="tl:dsArt_artTable,tl:dsArt_artRow" Grid.Row="0" Grid.Column="0">
<tl:xDataPanel.Items>
<tl:xDataPanelTextBoxItem BindingPath="artnr" x:Name="txtArtArtnr" LabelCaption="Artikelnummer" MaxLength="30" Grid.Row="0" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="bez1" x:Name="txtArtBez1" LabelCaption="Bezeichnung 1" MaxLength="40" Grid.Row="1" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="bez2" x:Name="txtArtBez2" LabelCaption="Bezeichnung 2" MaxLength="40" Grid.Row="2" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="suchwort" x:Name="txtArtSuchwort" LabelCaption="Suchwort" MaxLength="40" Grid.Row="3" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="text" x:Name="txtArtText" LabelCaption="Text" Grid.Row="4" Grid.Column="0" />
</tl:xDataPanel.Items>
</tl:xDataPanel>
XAML after setting Expression Binding for hiding condition (ExfresionBinding found on line 2):
<tl:xDataPanel x:Name="dpArt" DataSourcePath="dsArt.art" x:TypeArguments="tl:dsArt_artTable,tl:dsArt_artRow" Grid.Row="0" Grid.Column="0"
Visibility="{tl:ExpressionBinding Expression='iif(String(@artnr) == "1000", true, false)', CachingMode=Cached}">
<tl:xDataPanel.Items>
<tl:xDataPanelTextBoxItem BindingPath="artnr" x:Name="txtArtArtnr" LabelCaption="Artikelnummer" MaxLength="30" Grid.Row="0" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="bez1" x:Name="txtArtBez1" LabelCaption="Bezeichnung 1" MaxLength="40" Grid.Row="1" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="bez2" x:Name="txtArtBez2" LabelCaption="Bezeichnung 2" MaxLength="40" Grid.Row="2" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="suchwort" x:Name="txtArtSuchwort" LabelCaption="Suchwort" MaxLength="40" Grid.Row="3" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="text" x:Name="txtArtText" LabelCaption="Text" Grid.Row="4" Grid.Column="0" />
</tl:xDataPanel.Items>
</tl:xDataPanel>
Based on this example the xDataPanel (x:Name=dpArt) will be visible if the binding(@artnr) has the value “1000”, if not, the xDataPanel will be collapsed
Same as the one before we assume that the xDataPanel has the "DataSourcePath" set to "dsArt. art".
Based on this example we change the background color of the xDataPanelTextBoxItem (x:Name=txtArtNr). If the binding value (@artnr) is “1000” the color will be red, if not the color is changed to blue.
XAML after setting Binding Expression for Background color (ExfresionBinding found on line 4):
<tl:xDataPanel x:Name="dpArt" DataSourcePath="dsArt.art" x:TypeArguments="tl:dsArt_artTable,tl:dsArt_artRow" Grid.Row="0" Grid.Column="0">
<tl:xDataPanel.Items>
<tl:xDataPanelTextBoxItem BindingPath="artnr" x:Name="txtArtArtnr" LabelCaption="Artikelnummer" MaxLength="30" Grid.Row="0" Grid.Column="0"
Background="{tl:ExpressionBinding Expression='iif(String(@artnr) == "1000","Red", "Blue")', CachingMode=Cached}" />
<tl:xDataPanelTextBoxItem BindingPath="bez1" x:Name="txtArtBez1" LabelCaption="Bezeichnung 1" MaxLength="40" Grid.Row="1" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="bez2" x:Name="txtArtBez2" LabelCaption="Bezeichnung 2" MaxLength="40" Grid.Row="2" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="suchwort" x:Name="txtArtSuchwort" LabelCaption="Suchwort" MaxLength="40" Grid.Row="3" Grid.Column="0" />
<tl:xDataPanelTextBoxItem BindingPath="text" x:Name="txtArtText" LabelCaption="Text" Grid.Row="4" Grid.Column="0" />
</tl:xDataPanel.Items>
</tl:xDataPanel>
Result:
We assume that the xDataPanel has the "DataSourcePath" set to "dsArt.arbpl_afo"
XAML initially:
<tl:DxDataGrid Grid.Row="1" Grid.Column="0" Uid="60eec249-0b05-4f3c-94be-cf3fae6b1cae" Name="dxgarbpl_afo" Grid.ColumnSpan="3" DataSourcePath="dsArt.arbpl_afo" x:TypeArguments="tl:dsArt_arbpl_afoTable,tl:dsArt_arbpl_afoRow" RowBackgroundColorBinding="{tl:ExpressionBinding Expression='', CachingMode=Cached}">
<tl:DxTextBoxColumn x:Name="tbAfoNrDG" Uid="def49f3e-5573-4fc4-a896-975b4e5e2c4f" Width="50" IsReadOnly="True" BindingPath="afo_nr" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="AFO" BindingFormat="Integer"></tl:DxTextBoxColumn>
<tl:DxComboBoxColumn x:Name="tbAfoTypDG" Uid="18b82a51-1749-4de4-8fb7-60dbbb6aeded" Width="88" BindingPath="typ" HorizontalHeaderAlignment="Center" Header="Typ">
<tl:DxComboBoxColumn.Items>
<ComboBoxItem Tag="10" Content="Standard" Uid="f1261d37-50d8-4ae9-a975-40508634e295" />
<ComboBoxItem Tag="20" Content="Alternativ" Uid="ee703f29-1ac9-4fde-b739-3c9673008f01" />
</tl:DxComboBoxColumn.Items>
</tl:DxComboBoxColumn>
<tl:DxBlueArrowColumn Name="tbAfoArbgkatDGBlueArrow" IsReadOnly="True" Uid="db634be0-d055-40af-8ea0-d4ec560c165e" Width="20" />
<tl:DxTextBoxSearchColumn x:Name="tbsAfoArbgkatDG" Uid="4da61b69-4e38-4d65-a92a-42c8a72f6c80" Width="70" IsReadOnly="True" BindingPath="arbgkat_nr" HorizontalHeaderAlignment="Center" Header="Arbgkat-ID" SearchDefinitionID="arbgkat" RetrieveField="id" CharacterCasing="Upper"></tl:DxTextBoxSearchColumn>
<tl:DxTextBoxColumn x:Name="tbAfoBez1DG" Uid="b5b5222c-711b-4fa8-8218-381e59702e21" IsReadOnly="True" BindingPath="bez1" HorizontalAlignment="Left" HorizontalHeaderAlignment="Center" Header="Bezeichnung 1" MaxLength="40"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoBez2DG" Uid="4460a035-b10d-4d51-8a31-face4dd4b978" IsReadOnly="True" BindingPath="bez2" HorizontalAlignment="Left" HorizontalHeaderAlignment="Center" Header="Bezeichnung 2" MaxLength="40"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTRDG" Uid="f6791620-28e4-4048-89cc-d067e112f1d6" Width="80" IsReadOnly="True" BindingPath="tr" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Rüstzeit (Min)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTEDG" Uid="e3a75ef3-e69a-4eff-bf97-4343825ae23e" Width="90" IsReadOnly="True" BindingPath="te" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Stückzeit (Min)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoStueckProTEDG" Uid="dfbb4ab8-a1aa-4e67-a593-8f32361b71e7" IsReadOnly="True" BindingPath="stueck_pro_te" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Stück pro TE" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTDDG" Uid="df9a834e-5af9-467a-b9f8-a264a8ae1731" Width="60" IsReadOnly="True" BindingPath="tf" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="TF (Tage)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoRueckmFaktorDG" Uid="7c912ddc-0b1b-4545-b484-aed9478efd61" IsReadOnly="True" BindingPath="rueckm_faktor" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="RM-Faktor" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxLookupColumn x:Name="lgArtInfoArbplAfoMsteinAfoDG" Uid="a4360935-cd71-4f23-9f02-f13ee787b1a9" IsReadOnly="True" BindingPath="mstein_intafo_nr" HorizontalHeaderAlignment="Center" Header="Meilenstein-AFO" GridDef="lg_abbuchenafo" GridSource="xBusObj" SelectedValuePath="intafo" RefreshSelectedValueOnDataSourceChanged="True"></tl:DxLookupColumn>
</tl:DxDataGrid>
Using expression to change the background color of the row based on “typ” of the row. In this case we need to set he binding to the property of the DxDataGrid(x:Name=” dxgarbpl_afo”) called “RowBackgroundColorBinding”
In this case if the binding(@RowData.Row.typ) value is 20, the background-color of the grid row will pe LightGreen, if the value different the color will be set to null.
When using the expression on the DxDataGrid rows, always use @RowData.Row.field_name.
XAML after Expression Binding was set (ExfresionBinding found on line 2):
<tl:DxDataGrid Grid.Row="1" Grid.Column="0" Uid="60eec249-0b05-4f3c-94be-cf3fae6b1cae" Name="dxgarbpl_afo" Grid.ColumnSpan="3" DataSourcePath="dsArt.arbpl_afo" x:TypeArguments="tl:dsArt_arbpl_afoTable,tl:dsArt_arbpl_afoRow"
RowBackgroundColorBinding="{tl:ExpressionBinding Expression='iif(Int(@RowData.Row.typ) == 20, "LightGreen", null)', CachingMode=Cached}">
<tl:DxTextBoxColumn x:Name="tbAfoNrDG" Uid="def49f3e-5573-4fc4-a896-975b4e5e2c4f" Width="50" IsReadOnly="True" BindingPath="afo_nr" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="AFO" BindingFormat="Integer"></tl:DxTextBoxColumn>
<tl:DxComboBoxColumn x:Name="tbAfoTypDG" Uid="18b82a51-1749-4de4-8fb7-60dbbb6aeded" Width="88" BindingPath="typ" HorizontalHeaderAlignment="Center" Header="Typ">
<tl:DxComboBoxColumn.Items>
<ComboBoxItem Tag="10" Content="Standard" Uid="f1261d37-50d8-4ae9-a975-40508634e295" />
<ComboBoxItem Tag="20" Content="Alternativ" Uid="ee703f29-1ac9-4fde-b739-3c9673008f01" />
</tl:DxComboBoxColumn.Items>
</tl:DxComboBoxColumn>
<tl:DxBlueArrowColumn Name="tbAfoArbgkatDGBlueArrow" IsReadOnly="True" Uid="db634be0-d055-40af-8ea0-d4ec560c165e" Width="20" />
<tl:DxTextBoxSearchColumn x:Name="tbsAfoArbgkatDG" Uid="4da61b69-4e38-4d65-a92a-42c8a72f6c80" Width="70" IsReadOnly="True" BindingPath="arbgkat_nr" HorizontalHeaderAlignment="Center" Header="Arbgkat-ID" SearchDefinitionID="arbgkat" RetrieveField="id" CharacterCasing="Upper"></tl:DxTextBoxSearchColumn>
<tl:DxTextBoxColumn x:Name="tbAfoBez1DG" Uid="b5b5222c-711b-4fa8-8218-381e59702e21" IsReadOnly="True" BindingPath="bez1" HorizontalAlignment="Left" HorizontalHeaderAlignment="Center" Header="Bezeichnung 1" MaxLength="40"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoBez2DG" Uid="4460a035-b10d-4d51-8a31-face4dd4b978" IsReadOnly="True" BindingPath="bez2" HorizontalAlignment="Left" HorizontalHeaderAlignment="Center" Header="Bezeichnung 2" MaxLength="40"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTRDG" Uid="f6791620-28e4-4048-89cc-d067e112f1d6" Width="80" IsReadOnly="True" BindingPath="tr" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Rüstzeit (Min)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTEDG" Uid="e3a75ef3-e69a-4eff-bf97-4343825ae23e" Width="90" IsReadOnly="True" BindingPath="te" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Stückzeit (Min)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoStueckProTEDG" Uid="dfbb4ab8-a1aa-4e67-a593-8f32361b71e7" IsReadOnly="True" BindingPath="stueck_pro_te" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Stück pro TE" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTDDG" Uid="df9a834e-5af9-467a-b9f8-a264a8ae1731" Width="60" IsReadOnly="True" BindingPath="tf" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="TF (Tage)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoRueckmFaktorDG" Uid="7c912ddc-0b1b-4545-b484-aed9478efd61" IsReadOnly="True" BindingPath="rueckm_faktor" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="RM-Faktor" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxLookupColumn x:Name="lgArtInfoArbplAfoMsteinAfoDG" Uid="a4360935-cd71-4f23-9f02-f13ee787b1a9" IsReadOnly="True" BindingPath="mstein_intafo_nr" HorizontalHeaderAlignment="Center" Header="Meilenstein-AFO" GridDef="lg_abbuchenafo" GridSource="xBusObj" SelectedValuePath="intafo" RefreshSelectedValueOnDataSourceChanged="True"></tl:DxLookupColumn>
</tl:DxDataGrid>
Result:
Using the same expression, but this time on the DxComboBoxColumn(x:Name=”tbAfoTypDG”) will change only the color of the cell.
XAML after Expression Binding was set (ExfresionBinding found on line 4):
<tl:DxDataGrid Grid.Row="1" Grid.Column="0" Uid="60eec249-0b05-4f3c-94be-cf3fae6b1cae" Name="dxgarbpl_afo" Grid.ColumnSpan="3" DataSourcePath="dsArt.arbpl_afo" x:TypeArguments="tl:dsArt_arbpl_afoTable,tl:dsArt_arbpl_afoRow" RowBackgroundColorBinding="{tl:ExpressionBinding Expression='', CachingMode=Cached}" RowFontStyleBinding="{tl:ExpressionBinding Expression='', CachingMode=Cached}">
<tl:DxTextBoxColumn x:Name="tbAfoNrDG" Uid="def49f3e-5573-4fc4-a896-975b4e5e2c4f" Width="50" IsReadOnly="True" BindingPath="afo_nr" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="AFO" BindingFormat="Integer"></tl:DxTextBoxColumn>
<tl:DxComboBoxColumn x:Name="tbAfoTypDG" Uid="18b82a51-1749-4de4-8fb7-60dbbb6aeded" Width="88" BindingPath="typ" HorizontalHeaderAlignment="Center" Header="Typ"
BackgroundColorBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.typ) == 20,"LightGreen", null)', CachingMode=Cached}">
<tl:DxComboBoxColumn.Items>
<tl:xComboBoxItem Tag="10" Uid="2de1c620-1982-442b-a157-a6efb8f290b7">Standard</tl:xComboBoxItem>
<tl:xComboBoxItem Tag="20" Uid="3d05d3fa-adee-4e77-b0cb-6b7fa2577c99">Alternativ</tl:xComboBoxItem>
</tl:DxComboBoxColumn.Items>
</tl:DxComboBoxColumn>
<tl:DxBlueArrowColumn Name="tbAfoArbgkatDGBlueArrow" IsReadOnly="True" Uid="db634be0-d055-40af-8ea0-d4ec560c165e" Width="20" />
<tl:DxTextBoxSearchColumn x:Name="tbsAfoArbgkatDG" Uid="4da61b69-4e38-4d65-a92a-42c8a72f6c80" Width="70" IsReadOnly="True" BindingPath="arbgkat_nr" HorizontalHeaderAlignment="Center" Header="Arbgkat-ID" SearchDefinitionID="arbgkat" RetrieveField="id" CharacterCasing="Upper"></tl:DxTextBoxSearchColumn>
<tl:DxTextBoxColumn x:Name="tbAfoBez1DG" Uid="b5b5222c-711b-4fa8-8218-381e59702e21" IsReadOnly="True" BindingPath="bez1" HorizontalAlignment="Left" HorizontalHeaderAlignment="Center" Header="Bezeichnung 1" MaxLength="40"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoBez2DG" Uid="4460a035-b10d-4d51-8a31-face4dd4b978" IsReadOnly="True" BindingPath="bez2" HorizontalAlignment="Left" HorizontalHeaderAlignment="Center" Header="Bezeichnung 2" MaxLength="40"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTRDG" Uid="f6791620-28e4-4048-89cc-d067e112f1d6" Width="80" IsReadOnly="True" BindingPath="tr" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Rüstzeit (Min)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTEDG" Uid="e3a75ef3-e69a-4eff-bf97-4343825ae23e" Width="90" IsReadOnly="True" BindingPath="te" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Stückzeit (Min)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoStueckProTEDG" Uid="dfbb4ab8-a1aa-4e67-a593-8f32361b71e7" IsReadOnly="True" BindingPath="stueck_pro_te" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="Stück pro TE" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoTDDG" Uid="df9a834e-5af9-467a-b9f8-a264a8ae1731" Width="60" IsReadOnly="True" BindingPath="tf" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="TF (Tage)" IsEnabledBinding="{tl:ExpressionBinding Expression='iif(int(@RowData.Row.arbgkat_wz_afo) == 1, false, true)', CachingMode=Cached}" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxTextBoxColumn x:Name="tbAfoRueckmFaktorDG" Uid="7c912ddc-0b1b-4545-b484-aed9478efd61" IsReadOnly="True" BindingPath="rueckm_faktor" HorizontalAlignment="Right" HorizontalHeaderAlignment="Center" Header="RM-Faktor" BindingFormat="Quantity"></tl:DxTextBoxColumn>
<tl:DxLookupColumn x:Name="lgArtInfoArbplAfoMsteinAfoDG" Uid="a4360935-cd71-4f23-9f02-f13ee787b1a9" IsReadOnly="True" BindingPath="mstein_intafo_nr" HorizontalHeaderAlignment="Center" Header="Meilenstein-AFO" GridDef="lg_abbuchenafo" GridSource="xBusObj" SelectedValuePath="intafo" RefreshSelectedValueOnDataSourceChanged="True"></tl:DxLookupColumn>
</tl:DxDataGrid>
Result: