StringFormat in XAML, WPF : Currency Formatting - wpf

How can i obtain currency formatting according to my country i.e indian rupee, INR or Rs ??
Please tell me the way to achieve this ??
Right now when i use StringFormat="{}{0:C}", "$" is being used
I have gone through this link and i am able to achieve the desired result but i am worried about using this in my project. Is this code safe ??
What does this line mean in the above link "when you test functionality related to settings change it’s important you start the program directly from a folder window, if you run it from within Visual Studio or any other program you may get incorrect results."

You can specify the culture in your binding like this:
TextBlock Text="{Binding Value, StringFormat=C, ConverterCulture=nl-BE}"
nl-BE is belgian culture, you can exchange it with Indian culture info, I don't know that ;-)

Or you can set your current thread to the right culture, so you will use it everywhere in your application:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("hi-IN");

Related

How to set Silverlight 5 CurrentCulture & CurrentUICulture separately on DatePicker & TimePicker Control?

I have set two different cultures to the thread as:
Thread.CurrentThread.CurrentCulture = "fi-FI"
Thread.CurrentThread.CurrentUICulture = "en-Us"
But the calender text is shown in Finnish culture.
I need to keep the Text(Translations) based on CurrentUICulture and Text Format based on CurrentCulture.
Can you please suggest how can it be done for it?
That is not possible. The Calendar control only reacts to the CurrentCulture value. CurrentUICulture is used by the ResourceManager to load up different strings, images etc. used in the UI, but that is not where the day/month names are stored. They are part of the .NET framework itself. To get the functionality you want you will have to write your own implementation of the DatePicker and/or TimePicker controls. Perhaps you could download the code for the Silverlight Toolkit and use that as a base for your own implementation. What you are looking for is basically a way of overriding the names of months and days manually. Maybe it is even possible to extend the controls and add that functionality on top, but I doubt it.

With the Telerik Silverlight controls, how can I cast a RadMaskedTextBox as a TextBox

I am trying to determine if a Telerik RadMaskedTextBox allows multiline input.
I the debugger, I was able to find and check the .AcceptsReturn property of the underlying textbox, using:
((System.Windows.Controls.TextBox)(((Telerik.Windows.Controls.RadMaskedTextBox)(this)).textBox)).AcceptsReturn;
However, when I paste that into my C# code, the compiler complains that RadMaskedTextBox cannot be cast as a TextBox
A little weird, since the Debugger allows it.
The debugger also allows:
((System.Windows.Controls.TextBox)(((Telerik.Windows.Controls.RadMaskedTextBox)(this)).textBox)).TextWrapping
this the compiler complains about
Any ideas?
I tried to do this in the past (sorry can't remember the exact way to go about this) but I had to traverse the object and find the textbox control. If I can find the project where I did it I will update my answer.
From the Telerik Support Forum:
The underlying TextBox is of type ExtendedTextBox. You can access it like so:
var innerBox = this.masktextBox.ChildrenOfType<Telerik.Windows.Controls.MaskedTextBox.ExtendedTextBox>().FirstOrDefault();

How to supress WPF tool tips?

Is there a way to supress WPF tool tips, other than by setting their content to null?
I am extending the Calendar control to provide date highlighting, using Charles Petzold's MSDN article as a guide. As per the article, I use a value converter to return a string if a date on in the Calendar was found in a date list. The string (number of appointments for the day, for example) is displayed as a tool tip when the mouse is over the date. If the date wasn't found in the list, the value converter returns null.
Overall, it's pretty cool, but I'd like to provide an option to turn the tool tips off and just show highlighting. I am already using a null value when a date is not found, so that a tooltip is not displayed for that date. The null value also supresses the highlighting for that date. So, I can't simply return a blanket null if tool tips are turned off, because it would turn off the highlighting, as well.
I tried creating the tool tip in a separate tag and giving it a name, so that I could use a data trigger to turn it on and off. No go-- a tool tip is considered a property, and while it will compile as a separate object, it throws a runtime exception.
I also tried returning a coded value, 'NOSHOW' if the date was not found in the date list, so that I could use null to supress tool tips. Unfortunately, that gives every unhighlighted date a tool tip that says NOSHOW.
So, at this point I am scratching my head. Any suggestions as to how I can get this done? Thanks for your help!
ToolTipService.IsEnabled=False
<TextBox ToolTipService.IsEnabled="False" />

Silverlight (RIA Services) spontaneous culture changing

My RIA enabled Silverlight Application is setting the thread culture in the App constructor (this is absolutley okay since it is an intranet application and will never ever be used by someone who is not german):
public App() {
InitializeComponent();
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
}
It does what it should, the DataForms are displaying datetime values in german notation. BUT: it is spontaneously changing to en-US notation when navigating between items in the data source that is bound to the DataForm. Why?
It seems that the thread culture is not inherited by every control. Just for fun I displayed the Language of the control, and it was alwas set to en-US. To solve this, I hard coded the language de-DE in the style for the DataForm.
The same problem was described by Hannes (in german). Surprisingly in this case it was exactly the other way round: the DataForm was german, but the grid was english.
As Marc Wittke said, the thread culture is not inherited by every control (why on earth???)
Any way, you do not need to hardcode the values, this put this line in your Control constructor:
Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name);
And you control will use the CurrentCulture.
Cheers,
André

Silverlight Date Formats

I'm getting some very strange date formatting issues in my Silverlight application. My local culture is set to UK, yet I am consistently seeing US dates popping up all over the place. I can easily hardcode these to UK format in specific loactions using:
<UserControl ... Language="en-GB"...>
But as I'm sure you'd all agree this is a terrible thing to do.
I have tried setting the Lanaguage to en-GB in the main application and this has partial success. I have also tried Justin Angels suggestion (posted here: How to change date format in Silverlight DatePicker control?), again only partial success.
An example of the issue can be seen here:
http://lh3.ggpht.com/%5FL9TmtwXFtew/Sw5aVZJfG1I/AAAAAAAAGkI/6jYnsB91HjI/image%5Fthumb%5B1%5D.png http://lh3.ggpht.com/%5FL9TmtwXFtew/Sw5aVZJfG1I/AAAAAAAAGkI/6jYnsB91HjI/image%5Fthumb%5B1%5D.png
The datagrid on the parent page shows UK formatting, whilst the information in the ChildWindow shows US formatting ...grrrr
Anyone have a definitive solution for solving this across a whole application?
Thanks,
Mark
You can data bind Language property of the root visual element. Take a look at my question here:
How to switch UI Culture of data binding on the fly in Silverlight
Can you not use the SelectedDateFormat property of the datepicker? If you want to do this once could you not create your own usercontrol that derives from the original with this value preset, then use your derived control throughout your app?
Kindness,
Dan
Shot in the dark, but does changing the browser's Language Preference make a differnence? I.e. in IE Tools-->Internet Options-->Languages.
HTH
Mark
You can set the date format for your entire application in the application start up event as follows.This will override any regional settings on the users machine
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = dd/MM/yyyy";

Resources