Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I perform formating in Databound field?

Posted on 2009-07-07
10
Medium Priority
?
361 Views
Last Modified: 2013-11-12
I have a text block that I am doing some basic databinding and it works well but I want to have the databound item formated to currency, Can you do this in the XAML?

I have included my code below.
<TextBlock Height="21" Name="txtYTDTotal" Text="{Binding YTD_Total, Mode=TwoWay}" />

Open in new window

0
Comment
Question by:jmarbutt
  • 4
  • 3
  • 2
9 Comments
 
LVL 16

Accepted Solution

by:
TSmooth earned 2000 total points
ID: 24803544
Yes, look into using a ValueConverter (IValueConverter interface). Here's an article to get you started:
http://www.silverlight-help.com/tips/kentucker/09-03-27/Formatting_bound_data_in_Silverlight_2.aspx
0
 
LVL 8

Expert Comment

by:unmeshdave
ID: 24806397
well normally valueconverter u have to use when u want to display something based on field value (ie if each different value have different formating).
for simple formatting like this,
you can use Stringformat attribute of Binding.
as the attached code.
http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx  

<TextBlock Height="21" Name="txtYTDTotal" Text="{Binding YTD_Total, StringFormat={}{0:C}, Mode=TwoWay}" />
 

Open in new window

0
 
LVL 2

Author Comment

by:jmarbutt
ID: 24806926
unmeshdave,

I get an error of

"The property 'StringFormat' was not found in type 'Binding'"

When I try your solution, I am missing something simple.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 8

Expert Comment

by:unmeshdave
ID: 24806941
it comes with .Net 3.5 SP1. so make sure u have installed that.
0
 
LVL 8

Expert Comment

by:unmeshdave
ID: 24806948
0
 
LVL 16

Expert Comment

by:TSmooth
ID: 24807049
unmeshdave, I think he's working with Silverlight which does not support the "StringFormat" binding parameter. That's why I went with IValueConverter.

jmarbutt,
If you are using Silverlight, you will need to do it the way I originally posted and you don't need to install .NET 3.5 SP1. If you are using WPF, then unmeshdave's answer should work and be easier.
0
 
LVL 8

Expert Comment

by:unmeshdave
ID: 24807174
yes if he is using SL then Stringformat will not work as of now.
jmarbutt:
If you are using SL you need to use valueconverter as TSmooth Suggessted.
0
 
LVL 2

Author Comment

by:jmarbutt
ID: 24807212
Yeah that should work then with SL. Sorry for the mix up.
0
 
LVL 16

Expert Comment

by:TSmooth
ID: 25117445
From what I can tell following this thread, jmarbutt used my initial solution.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question