Category / Section
How to change the measure caption in the OlapGrid?
1 min read
The Measure Caption can be changed to Internet Sales Amount of the OLAP Grid by utilizing the TemplateCell property of the OLAP Grid as illustrated in the following code example.
XAML
<Grid.Resources> <viewModel:TextConverter x:Key="textconverter"></viewModel:TextConverter> <Style x:Key="colStyle" TargetType="{x:Type olapgrid:OlapGridTemplateCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type olapgrid:OlapGridTemplateCell}"> <StackPanel Grid.Column="1" Orientation="Horizontal" Background="#FF119EDA"> <TextBlock Grid.Column="1" Margin="3,4,2,0" Text="{Binding Converter={StaticResource textconverter}}" Foreground="White" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Calibri" FontSize="12"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </Grid.Resources> <olapgrid:OlapGrid Margin="5,5,5,5" x:Name="olapGrid1" DataContext="{StaticResource olapGridDataContext}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowHeaderCellsToolTip="True" OlapDataManager="{Binding GridDataManager}"> <olapgrid:OlapGrid.ColumnHeaderStyle> <olapgrid:OlapGridCellStyle Style="{StaticResource colStyle}"/> </olapgrid:OlapGrid.ColumnHeaderStyle> </olapgrid:OlapGrid>
C#
public class TextConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string text = null; PivotCellDescriptor cellinfo = value as PivotCellDescriptor; if (cellinfo != null && cellinfo.DoubleValue == 0.0) { if (cellinfo.CellValue == "Internet Sales Amount") { text = "IntSalAmt"; } else { text = cellinfo.CellValue; } } else { text = cellinfo.CellValue; } return text; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
VB
Public Class TextConverter Implements IValueConverter Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Dim text As String = Nothing Dim cellinfo As PivotCellDescriptor = value as PivotCellDescriptor If cellinfo <> Nothing And cellinfo.DoubleValue = 0.0 Then If cellinfo.CellValue = "Internet Sales Amount" Then text = "IntSalAmt" Else text = cellinfo.CellValue End If Else text = cellinfo.CellValue End If Return text End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Throw New NotImplementedException() End Function End Class