Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I perform formating in Databound field?

Posted on 2009-07-07
10
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
10 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

670 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