Hi,
for visualizing errors in my DataPresenter I use a DataTemplate:
<DataTemplate x:Key="{x:Static igDP:DataPresenterBase.DataErrorContentTemplateKey}" > <Border x:Name="cellBorder" > <Grid x:Name="panel"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Border x:Name="errorBorder" BorderThickness="1" BorderBrush="#FF5D696D" Grid.ColumnSpan="2" Visibility="Collapsed" SnapsToDevicePixels="True"> <Border x:Name="innerBorder" BorderThickness="1" SnapsToDevicePixels="True"/> </Border> <Control x:Name="errorIcon" Visibility="Collapsed" Margin="4,0,0,0" Style="{DynamicResource {x:Static igDP:DataPresenterBase.DataErrorIconStyleKey}}" /> <ContentPresenter x:Name="content" ContentTemplate="{x:Null}" Grid.Column="1" Margin="0,0,2,0" /> </Grid> </Border> <DataTemplate.Triggers> <!--Value was set manually--> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=Host.HasDataError}" Value="true" /> <Condition Binding="{Binding Path=Host.DataError, Converter={StaticResource validationErrorConverter}, ConverterParameter={x:Static BL:SchemaValidator.ManualValue}}" Value="True" > </Condition> </MultiDataTrigger.Conditions> <Setter TargetName="errorIcon" Property="Visibility" Value="Collapsed" /> <Setter TargetName="cellBorder" Property="Background" Value="#FF8080ff" /> </MultiDataTrigger> <!--actual range is to low--> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=Host.HasDataError}" Value="true" /> <Condition Binding="{Binding Path=Host.DataError}" Value="{x:Static BL:SchemaValidator.ActualRangeIsToLow}" /> </MultiDataTrigger.Conditions> <Setter TargetName="errorIcon" Property="Visibility" Value="Collapsed" /> <Setter TargetName="cellBorder" Property="TextBlock.Foreground" Value="Red" /> <Setter TargetName="cellBorder" Property="TextBlock.TextAlignment" Value="Left" /> <Setter TargetName="cellBorder" Property="TextBlock.TextDecorations" Value="Underline" /> </MultiDataTrigger> </DataTemplate.Triggers> </DataTemplate>
All stylings work as expected but the two rows in the DataTrigger
<Setter TargetName="cellBorder" Property="TextBlock.TextAlignment" Value="Left" /><Setter TargetName="cellBorder" Property="TextBlock.TextDecorations" Value="Underline" />
have no effect on the cells.
How can I change Text styling (alignement/decorations) in this scenario for a single cell?
Thank you. Using styles it works fine.
You can do it like so:
<Style TargetType="{x:Type igEditors:XamTextEditor}" >
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="Padding" Value="0" />...
since outside edit mode the text element autofits its content and this is why the TextAlignment is not working.
It applies this style only for cells with errors and I left the Foreground setting by mistake, it is not supposed to work.
Hope this helps.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support
May it be, that the editor in the cell is only a XamTextEditor when there is a DataError available? It seems that all style settings only apply to cells which have a DateError set.
<Style TargetType="{x:Type Editors:XamTextEditor}" > <Setter Property="Foreground" Value="Green" /> <Style.Triggers> <DataTrigger Binding="{Binding Path=DataError, RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Converter={StaticResource validationErrorConverter}, ConverterParameter={x:Static BL:SchemaValidator.ActualRangeIsToLow}}" Value="True"> <Setter Property="Foreground" Value="Red" /> </DataTrigger> </Style.Triggers></Style>
In this example none of the rows are green. There are only red and black cells.
Hallo,
thank you very much for the great answer. The underlining works fine, now :)
I tried to align the text in case of error to the left and in case of no error to the right. I'm not able to do this. I tried
<Style TargetType="{x:Type Editors:XamTextEditor}" > <Setter Property="Padding" Value="0" /> <Style.Resources> <Style TargetType="{x:Type Controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Underline" /> <Setter Property="TextAlignment" Value="Right" /> </Style> <Style TargetType="TextBox" > ...
But the SimpleTextBlocks seems to display numbers (double) always aligned to the left :(
Is there a way to change this behaviour?
Hello,
I have been looking into this issue for some time now and finally reached a solution. The setter you have used doesn’t work because since 10.3 the XamEditors no longer use a TextBlock, but rather an optimized Infragistics class called SimpleTextBlock. What you can do is add keyless styles to your DataTemplate’s ContnentPresenter.Resources for the XamEditors that are going to be assigned to it:
<ContentPresenter.Resources>
<Style TargetType="{x:Type igEditors:XamCurrencyEditor}" >
<Setter Property="Padding" Value="0" />
<Style.Resources>
<Style TargetType="{x:Type igWindows:SimpleTextBlock}">
<Setter Property="TextDecorations" Value="Underline" />
</Style>
</Style.Resources>
<Style TargetType="{x:Type igEditors:XamDateTimeEditor}" >
<Style TargetType="TextBox" >
<Setter Property="Foreground" Value="Red" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=HasDataError, RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}}" Value="True" >
<Setter Property="Foreground" Value="BlueViolet" />
<Setter Property="Margin" Value="-2,-1,0,-2" />
<Setter Property="TextDecorations" >
<Setter.Value>
<TextDecorationCollection >
<TextDecoration />
</TextDecorationCollection>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</ContentPresenter.Resources>
</ContentPresenter>
I even managed to get the XamTextEditor to be underlined while in edit mode.
Hope this helps. Please let me know if you require any further assistance on the matter.