I am developing an e-commerce administration panel in WPF. I would like to display currency values in PLN (Polish Złoty). Format {0:C} gives output in USD ($1.000). Is there a way to change this behaviour or do I have to write my custom format to accomplish this?
edit:
Why this is so if my windows culture info and location are both set to Polish/Poland?
Try to pass CultureInfo in your String Format.
string money = String.Format(CultureInfo.GetCultureInfo("pl"), "{0:C}", 30.7m);
Console.WriteLine(money);
EDIT: if you are in WPF then this should do the trick:
this.Language = XmlLanguage.GetLanguage("pl");
or
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("pl")));
You sholud add only xml:lang="pl-PL" in your <Window> tag in MainWindows.xaml. Simple as that!
Related
I have a WindowsForm application having all text(On form labels/buttons/other controls) written in the Norwegian language. I want to convert all text in English using localization. Is there any way in Devexpress where we can convert all text into English without writing the meaning of every text in a resource file manually?
For example:- In the attachment, "Brukernavn" is hardcoded on a label. I want to auto-convert it into English without assigning its value in English-ResourceFile. What should be the approach in Devexpress localization?
I'm not aware of any Devexpress method to do this. A good solution would be to actually do the work of building a localisation file for English which would work like following.
Add a InternationlisationLayer to your application.
This layer
scours the application to locate all Controls you would possible want
to translate.
After finding all Controls you have to match their
Text values to the translated text.
After finding a matching English
text you will have to replace the Text Property on these Controls.
If you want to avoid building a proper Localisation system a far easier solution is explained below.
Make a List of type and fill it with all control texts you want translated.
Translate the strings and add format them as such that you have a Dictionary of type (where Key would be the original text and Value being the translated text).
At application Start get a list of all Controls you want to translate and do something like the following:
public static IEnumerable<System.Windows.Forms.Control> GetAllControlsOfType(this System.Windows.Forms.Control control, Type type)
{
var controls = control.Controls.Cast<System.Windows.Forms.Control>();
return controls.SelectMany(ctrl => GetAllControlsOfType(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
public void DoTranslation()
{
var ctrls = this.GetAllControlsOfTypes(new List<Type>() { typeof(Label), typeof(Button) });
foreach (var ctr in ctrls)
{
var element = dict.FirstOrDefault(i => i.Key == ctr.Text);
ctr.Text = element.Value;
}
}
Im learning XAML with microsoft visual studio 2013 wpf application.
I want to make a textblock display my Project Name from a some kind of resource(?) - I want to make a template :) .
Thank you for help in advance :) .
string name = Assembly.GetEntryAssembly().GetName().Name;
or
string name = Assembly.GetExecutingAssembly().GetName().Name;
Alternatively, you can get the Assembly object from any known type in the assembly:
Assembly assy = typeof({class name here}).Assembly;
This also allows another option to get the the name only:
string name = typeof({class name here}).Assembly.GetName().Name;
Here's the link
When I set the Text property of RolesTextName from codebehind in a Silverlight5 app by doing:
RolesTextName.Text = "David & Goliath";
<TextBlock TextWrapping="Wrap">
<Span FontWeight="Bold">Roles:</Span>
<Span><Run x:Name="RolesTextName" /></Span>
</TextBlock>
Problem: I don't get the & symbol, just the actual text.
XAML is used to create an object graph that represents your user interface. When you modify the user interface by setting property values in code the XAML has already been processed and is no longer used. You should not do any XAML specific encoding when modifying the object graph from code. Encoding is only required in XAML because it is based on XML and you need a way to represents characters like &, < and > unambgiously.
So executing
RolesTextName.Text = "David & Goliath";
will set the text of the run to
David & Goliath
To achieve what you want simply execute this code insted:
RolesTextName.Text = "David & Goliath";
Hi im also quite new to XML, but I've had a similar problem in the past
This link gave me some insight, hope it can help you.
`<![CDATA[Wake & Bake]]>
http://www.w3schools.com/xmL/xml_cdata.asp
Is there an easy way to convert HTML to display in the new Windows Phone 7.1 (Mango) RichTextBox control. I'm mostly concerned about retaining links and images without using a web browser control.
thanks,
Sam
I would use HTML Agility pack to parse the HTML and transform each type of node in the equivalent in the Document namespace: http://htmlagilitypack.codeplex.com/
You need to handle the nested elements and depending of the level of conformity of the HTML, handling bad formatted content can be hard but HA is a good library.
There's a sample in the source code I think.
public void ConvertRtfToHtml()
{
System.Windows.Forms.WebBrowser webBrowser =
new System.Windows.Forms.WebBrowser();
webBrowser.CreateControl(); // only if needed
webBrowser.DocumentText = richTextBox1.Text;
while (webBrowser.DocumentText != richTextBox1.Text)
Application.DoEvents();
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
richTextBox2.Paste();
}
Today I'm playing with localization. I have a winforms app where I've set localizable to true on my screen, then I went and converted all the text to spanish as best as I could. So now I have my screen.resx and my screen.es.resx and everything looks good/bueno. How do I now run my app and have the spanish version come up? I tried going into regional and language options and setting my 'standards and formats' option to spanish. Now my dates are in spanish which is good, but the text on my app is still the english version. How do I get this thing to load with my screen.es.resx?
Did you set your applications Culture/UI Culture to Spanish?
In following code, en-US will be replaced by your UI culture and it will use appropriate resx file depending on the way you have them set up
HTH
System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo("en-US", false);
System.Threading.Thread.CurrentThread.CurrentUICulture = myCI;
System.Threading.Thread.CurrentThread.CurrentCulture = myCI;
You control which language resource that are used by setting the CurrentUICulture of the current thread. You will most likely also want to set the CurrentCulture (that controls number and date formats and such) (C# code):
// the following using statements must be present
// using System.Threading;
// using System.Globalization;
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("es-ES");
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
For a more detailed discussion on the difference between CurrentUICulture and CurrentCulture, there is a blog post by Michael Kaplan on the topic.