As you know LinkLabel control in WinForms supports selection of an area of text (stored in .resx) that will act as link by specifying start and position and length in LinkArea property. But localized text can and will change this exact values as in example below:
"Visit our page now!" [6, 7]
"Посетите нашу страничку сегодня!" [9, 13]
Is there a way to overcome this issue without using special characters and other messy workarounds?
LinkArea property is decorated with Localizable attribute and therefore it's localizable.
So if you set Localizable property of the Form to true, then you can set different value for localizable properties of controls for different languages. This way, property values will store in separate resource files for different cultures.
For more information and links to how to create multi-language windows forma application, take a look at:
How to make multi language app in winforms
Related
I'm getting into globalization and localization. I'm aware that I can set the localizable property of my form to true and that I'm able to edit the form for that specific culture. That's great. My question is am I able to, at the designer, load my resx values into their assigned winforms? My goal is to edit the size of my winform assets around the translated languages. This is, obviously, easier if I can see the translations in the designer. Attached is the code that change the text of my buttons at runtime, but my goal is have this take place during the design phase.
buttonTelescopeUp.Text = Resource.TeleUp;
buttonTelescopeDown.Text = Resource.TeleDown;
buttonTelescopeLeft.Text = Resource.TeleLeft;
buttonTelescopeRight.Text = Resource.TeleRight;
Form at runtime
Formin design
I have a problem of understanding with localization, hope you can help.
I create a winform app:
add a button
set the form Localizable property to True
set the form Language to Spanish
change the button's Text to "Vamos" and BackColor to "Green".
set the form Language to English
change the button's Text to "Go" and BackColor to "Yellow".
When I swap between Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("es"); and Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en"); the button Text DOES change from "Vamos" to “Go” but the BackColor is always set to “Yellow”.
My deduction is that Localizable = True tracks [control].Text property changes, and other changes such as [control].Location and [control].Size, but it does NOT track [control].BackColor or many other control property changes in the respective resx files.
Is this a bug? Is there a reference document to understand what IS and ISN'T being tracked? I can understand that BackColor is not something that is typically related to a language change but on that basis, size and location shouldn’t be either...so I am not clear on the rationale applied here...
Because of this limitation I am having to make certain localization changes via resx files and others manually via my on logic, feels a bit messy.
Thanks for your help.
[tested in VS 2012 and 2017 with equal behaviour]
A property is considered as localizable if it's decorated with Localizable(true) attribute. For example BackColor property is not localizable, but Text property is localizable.
When the designer generates code for your form, when you have enabled localization for the form, properties which are decorated with the Localizable(true) will be serialized to the resource file of the form. For the rest of the properties, their values will be serialized in code.
For more information and links to how to create multi-language windows forma application, take a look at:
How to make multi language app in winforms
Currently, I have a form named 'Form1' with 3 Lables, 3 Textboxs, 1 GridView with 10 columns.
I tried to use 'Localizable' attribute and set Language to English. But I have to go one-by-one control, change its text, and save, then the resource file will generate.
It makes me spend more time to apply for all controls.
Is there any way to add the resource file with fully controls more easier? We don't need to update the text for each control.
Thank you for your help.
Simple answer for your question is NO. There is no shortcut for this task. However, you should do it only for Forms (initially). VS creates the resource file and generate a few lines of codes when you set the Localizable property true just for the Form. Then you can go to the designer code and add the Localizable property for the rest of the controls if required.
It is possible to export Microsoft Visio drawings as a Website containing Silverlight content. This is described on this blog-post.
The output of such an export are the following:
xaml_1.xaml (contains the structure of the control)
data.xml (contains all text content such as labels, etc)
several java-script files
*.htm pages with a Silverlight container
other files such as *.css and images
I would like to integrate the exported XAML code into another existing Silverlight application. I found this blog-post telling me how to load XAML code dynamically during runtime.
What I would like to know is how to "merge" the XAML-file and the data.xml and how I can get a reference to the items of the XAML code, in order to change certain texts...
In the associated xaml js file (eg xaml_1.js) there's a handleMouseUp function that reads the shape ID from the (XAML) 'name' string and then calls OnShapeClick in frameset.js. This method, which is common to all of the js-based Save as web output types, then calls other methods to populate the details table or retrieve hyperlinks found in data.xml. If you have a look at the FindShapeXML function in frameset.js you'll see that it gets the appropriate data based on the page and shape IDs (note that shape IDs are unique to a page as per Visio itself).
In terms of creating data-bound or dynamic shape text, one workaround for the glyphs issue that #slfan highlights is prevent the text from being output. For example, prior to running Save As Web in Visio, you could loop through all of the shapes and set their HideText ShapeSheet cell to true. This will prevent all of the glyphs xaml being generated and you'll still have access to the text string in data.xml. I guess you wouldn't then benefit from the correct font scaling, but it depends on your scenario. If it was really important to get the scale right then you could parse the RenderTransform attribute (which is described in attribute syntax rather than property element syntax) of the glyph elements.
Glyphs are there (I'm guessing) because it mirrors how Visio works in the application ie in Visio you can select individual characters within a shape's text and apply different fonts and formatting, but if you don't need that, I'd be tempted to ditch the glyphs collection and just use a TextBlock as #slfan suggests.
I think you have to tweak the generated XAML a little bit. Unfortunately Visio generates glyphs for every single character. If you want to change the text at runtime, you will have to remove this glyphs and add the required controls (e.g. TextBlock) yourself.
You can load the XAML into Silverlight with XamlReader.Load. A good description you find here: http://blogs.silverlight.net/blogs/msnow/archive/2008/10/09/silverlight-tip-of-the-day-60-how-to-load-a-control-straight-from-xaml.aspx.
All JavaScript and HTML files you can ignore, the XML-file you need to identify your controls. The ID's in the XML refer to the corresponding elements in the XAML-file.
I'm using Microsoft Report Viewer in windows application and its datasource
is a custom class object. I have several Text fields and some are in different formats
(ie size of the font, underline, bold....) but several are grouped.
For these reason I would like to use a CSS (Cascading Style Sheet) class or some thing similar for formatting. (now I formatting each controls manually).
Is there a way to do this?
No, there is no way to do this. RDL, and all of the tools built around it (like ReportBuilder, BIDS, etc) have no concept of stylesheets of any kind.
The best solution is to select all the textboxes at once that you want all to be the same, then edit their properties in the property grid (in BIDS, Visual Studio or ReportBuilder). If you instead edit their properties through the property dialog, you must do it one at a time.
Probably the best you can do is to use expression parameters when you set the Font.
e.g. define report pararameter #FontSize and set default to 10
This allows you to override your default font size when you request the report by setting the report parameter.
I don't believe you can use CSS for a desktop windows application, your best bet is to look at the custom formatting for each cell of the ReportViewer