[Display(Name = "Account")]
public string accnt { get; set;}
[DisplayFormat(DataFormatString="#,##0.0000")]
public double cnOpened { get; set; }
7 Answers, 1 is accepted
In order to achieve the desired you would need to set the desired StringFormat in the Xaml definition of the needed AggregateDescription as demonstrated below:
<
pivot:PropertyAggregateDescription
PropertyName
=
"Quantity"
StringFormat
=
"#.#0"
/>
This will initially show the AggregateDescription with that format, however when modifing the Pivot at run time this format will be lost. So you would also need to hook to the PrepareDescriptionForField event of the provider in order to apply the format every time the fields in the FieldList are changed as shown below:
private
void
LocalDataSourceProvider_PrepareDescriptionForField(
object
sender, PrepareDescriptionForFieldEventArgs e)
{
var aggregateDescription = e.Description
as
PropertyAggregateDescriptionBase;
if
(e.DescriptionType == Telerik.Pivot.Core.DataProviderDescriptionType.Aggregate && aggregateDescription !=
null
&& aggregateDescription.PropertyName ==
"Quantity"
)
{
aggregateDescription.StringFormat =
"#.#0"
;
}
}
Hope this helps.
Regards,
Kalin
Telerik
Hi Kalin -
I would also like to setup default format strings for my aggregated values in my application. I am following the MVVM pattern, and am instantiating my LocalDataSourceProvider within the code of my view model. As a result, I cannot hook into the PrepareDescriptionForField event in my view's code-behind, but I understand I can use EventToCommandBehavior (http://docs.telerik.com/devtools/wpf/common-event-to-command-behavior.html) to setup a binding between the PrepareDescriptionForField event and a custom command in my view model to achieve this.
However, I am having trouble getting this to work. It seems the command is not firing when I make changes in my RadPivotFieldList. Can you offer an guidance or an example of wiring this up correctly?
My LocalDataSourceProvider is called CommissionDataProvider, and the relevant code snippet is shown here:
TestCommand = new RelayCommand(Test);
EventBinding eventBinding = new EventBinding();
eventBinding.Command = TestCommand;
eventBinding.EventName = "PrepareDescriptionForField";
eventBinding.RaiseOnHandledEvents = true;
eventBinding.PassEventArgsToCommand = true;
EventToCommandBehavior.GetEventBindings(CommissionDataProvider).Add(eventBinding);
Thanks,
Brett
As a follow-up,
I have also changed my DataProvider binding to TwoWay, but that did not help either.
<
pivot:RadPivotGrid
Grid.Row
=
"0"
Grid.Column
=
"0"
DataProvider
=
"{Binding Path=CommissionDataProvider, Mode=TwoWay}"
telerikControls:StyleManager.Theme
=
"Windows7"
HorizontalLayout
=
"Tabular"
VerticalLayout
=
"Compact"
RowSubTotalsPosition
=
"Bottom"
RowGrandTotalsPosition
=
"Bottom"
>
<
pivot:RadPivotGrid.RowGroupsExpandBehavior
>
<
pivot:GroupsExpandBehavior
Expanded
=
"False"
/>
</
pivot:RadPivotGrid.RowGroupsExpandBehavior
>
</
pivot:RadPivotGrid
>
<
pivot:RadPivotFieldList
Grid.Row
=
"0"
Grid.Column
=
"1"
DataProvider
=
"{Binding Path=CommissionDataProvider, Mode=TwoWay}"
telerikControls:StyleManager.Theme
=
"Windows7"
/>
Any guidance?
Thanks,
Brett
The reason for the EventToCommandBehavior not working in this scenario is that the behavior is designed to work only with UIElements and the LocalDataSourceProvider inherits from DependencyObject. So I'm afraid you won't be able to use it in this particular scenario.
If you have any other questions, please let us know.
Regards,
Kalin
Telerik
Hi Kalin -
Thank you for the reply. In this case, since I cannot use the EventToCommandBehavior functionality, what are my options for setting default format strings for the aggregate values, while still keeping the LocalDataSourceProvider in my view model?
Thanks,
Brett
Since you have the LocalDataSourceProvider defined in the ViewModel, wouldn't be suitable for you to hook to the event directly there? If you don't want to use events in the ViewModel you could implement an attached behavior for the LocalDataSourceProvider and do the hooking there.
Hope this helps.
Regards,
Kalin
Telerik
Hi Kalin -
Thank you! As you suggested, I was able to simply add the event handler in the code of my view model.
CommissionDataProvider =
new
LocalDataSourceProvider();
CommissionDataProvider.PrepareDescriptionForField += CommissionDataProvider_PrepareDescriptionForField;
I appreciate the help.
Best,
Brett