Il mio approccio era sbagliato. Avevo bisogno di usare IValueConverter e legare le proprietà Text e di primo piano in questo modo ...
type FixedDecimalConverter() =
interface IValueConverter with
member this.Convert(value, targetType, parameter, culture) =
match value :?> Double with
| Globals.DataGridHelper.IsNegative x ->
sprintf "(%.2f%%)" (Math.Abs x) :> obj
| Globals.DataGridHelper.IsPositive x ->
sprintf "%.2f%%" x :> obj
member this.ConvertBack(value, targetType, parameter, culture) = raise <| NotImplementedException()
type ForegroundValueConverter() =
interface IValueConverter with
member this.Convert(value, targetType, parameter, culture) =
match value :?> Double with
| Globals.DataGridHelper.IsNegative x -> Globals.DataGridHelper.redBrush :> obj
| Globals.DataGridHelper.IsPositive x -> Globals.DataGridHelper.greenBrush :> obj
member this.ConvertBack(value, targetType, parameter, culture) = raise <| NotImplementedException()
E il Xaml ...
<data:DataGridTemplateColumn Header="YTD v. Sector" x:Name="YTDvSector" Visibility="Collapsed">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextAlignment="Right" VerticalAlignment="Center"
Text="{Binding ytdSectorReturn.value, Converter={StaticResource fcFixedDecimalConverter}}"
Foreground="{Binding ytdSectorReturn.value, Converter={StaticResource fcForegroundValueConverter}}"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
e l'impianto idraulico ...
<UserControl.Resources>
<y:FixedDecimalConverter x:Key="fcFixedDecimalConverter" />
<y:ForegroundValueConverter x:Key="fcForegroundValueConverter" />
</UserControl.Resources>