Localize a WP7 application using MVVM Light - windows-phone-7

I'm using MVVM Light in my Windows Phone 7 application. The application is to be used in English and Spanish. Users can select a different language during runtime. I'm localizing the application using resource files. I've already been able to make the localization works, but only when I change the language from Settings. In the main page, I have a list for users to select the language during runtime, I'm setting the selected language to Thread.CurrentThread.CurrentCulture, but the text strings in the interface don't get updated. I have a set of properties in the ViewModel that I'm binding to the View to set the labels of the control, but something is missing. I've been reading that I need to implement the INotifyPropertyChanged in the ViewModel to make this works, but I don't know how to exactly do that nor if there is a different better way to implement this case using MVVM Light. Could anybody help me here please?

Hum, I wrote a blog post about it sometimes ago ( http://wp7wonders.wordpress.com/2010/10/17/localize-a-windows-phone-7-application/ - read the comments too!). The main point is that you have an object between the resource files and your viewmodels which allow to change the dynamically the language.

Related

How can I programmatically add xaml elements in Visual Studio 2017?

I have a C++/winrt project with a complex and dynamic xaml interface created in C++ code. Now I am moving to the latest VS 15.9.0 Preview 3, which has platform support for C++/Winrt and also allows use of the xaml designer in such a project. But I don't want to use the designer and have turned it off in Tools/Options/Xaml. The result is that none of my programmatic xaml elements appears. The project seems to expect me to enter these elements in a xaml code page, rather than using C++, e.g. Grid(), StackPanel(), view.RowDefinitions.Append(), view.SetRow() etc. The GeneratedFiles folder is now full of items that were not present in the previous project, yet can't be removed. Is it still possible to use the C++ interface for xaml, and what must be done to enable it if so? Thanks.
Ryan is correct: C++/winrt does support programmatic creation of xaml, and it works great. With the help of a couple of c++/winrt guys at MS I think I also know why my code was not doing anything. In the former version of my app I had declared MainPage as a C++ class, not a struct, and had assigned the starting Grid for the xaml by getting the current Window and setting currentWindow.Content(theGrid). But in the new template app MainPage is a struct, which might matter, and while setting window.Content that way no longer works, this does: this->Content(theGrid). Leaving aside some irrelevant issues about declarations in the BlankApp, this I think is the answer. Programmatic xaml works if you set that initial content as above.
Unfortunately, this is not the intended way to use this UI system. XAML-based UI systems are descendants of WPF, which relies on the Model-View-ViewModel (MVVM) pattern.
This pattern intends three types of classes to make up your application: Views, which are primarily written in XAML, and only deal with displaying data they are given; ViewModels, which are the wrapper and translator to give the views data, and to give the models commands; and lastly, Models, which are your backend business-logic classes.
Your instinct to not trust the designer is reasonable - it generates messy and unidiomatic XAML code. But it is an excellent way to preview the way your XAML code looks.
To get back to your specific situation, there are real problems in the library's API that will be serious roadblocks to programmatically define a UI in C++. Instead, you will want to use XAML to declare the UI. Adding and removing grid column definitions is not something that is well-supported, but using StackPanels and DockPanels is the normal way to do this.
If you have more specific questions, feel free to open a new question here, but do bear in mind that you may want to search first under the tags mvvm and wpf in addition to xaml, c++-winrt, and winrt.
If you have more questions that are rather broad and may be too broad for the main site here, feel free to join the WPF channel on chat, but bear in mind that most of us don't have experience in WinRT specifically.

Changing sap ui5 application locale dynamically in the application

I have two different language i.e English and German in my web app and user can change the language in application through a select box. Initially i am getting preferred language from the back-end and i am setting locale of the core as follows.
sap.ui.getCore().getConfiguration().setLanguage("//according to whatever is coming from back-end")
Now lets say initial language is English, if user open a control i.e sap.m.datepicker, calendar is being displayed in English. If user changes the language to German from the application i am again changing the language in the core as shown below:
sap.ui.getCore().getConfiguration().setLanguage("de-DE")
Now if user opens that same datepicker, it is being displayed in English instead of German and if user opens some another control or datepicker it is being rendered in German.
Page is not getting refreshed while changing the language in app.
Please suggest me a solution to dynamically change the locale of the controls.
Maybe my answer here helps a little.
The problem is that in many cases, maybe even in most cases, the standard UI5 controls detect the language only once when they get loaded. Very often, the control developers did not implement a "dynamic change" of the language. If you check the link I mentioned above you will see that there are ways to react on language changes, but very often this is not implemented for whatever reason.
However, I'm afraid to tell you that in your case the standard control might not support dynamic language changes out of the box (but I did not check the code). Also, it seems that the UI5 guys at SAP do not consider this as a bug (see this github issue). Such a pity...
I would suggest you use sap.ui.core.Core.attachLocalizationChanged(fnFunction, oListener) and add this to the onInit function of your controller.
From this, in your fnFunction rebuild the controls where you require the locale changes to be dynamic.
example:
onInit: function(oEvent) {
sap.ui.getCore().attachLocalizationChanged(this._handleLocalizationChanged, this);
},
_handleLocalizationChanged: function() {
// ... Some logic to re-build / set locale for the dynamic controls.
}
This is my interpretation of what should be done based on the information in the api

What is imgMain control in visual Basic 6?

I'm using a VB6 application as a reference and have come across imgMain. I'm assuming its an image control, however, I cannot find the object on any of the forms. It's used to load the image. I'm just not sure what's going on with this. I'm assuming its an IMAGE CONTROL, but I cannot find this on any of the forms? it's mentioned a lot of times in teh application as it lets you view incoming faxes and stuff.
Without having a look on source code i assume It might be custom user control that was created for some reasons probably to extend basic picturebox control.
One thing i can advise you is to further inspect code and dig to code of this custom control. If code for this control is not available then see what methods and properties instances of that particular control uses and compare them with regular picturebox.

Programatically setting control properties vs. using designer

Often, when I'm looking for information of how to set certain properties of controls (I'm using Visual Studio primarily, but this question does apply to any IDE), the examples I find normally involve programatically setting said properties.
Here's an example, using the DataGridView.DefaultCellStyle property on MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.defaultcellstyle(v=vs.110).aspx
So my question is: is it better for a programmer to modify these properties by code, or is it better to use the IDE itself to change them via the properties pane? I realize that doing it the latter way will result in auto-generated code anyway, but it will be "somewhere else" in relation to the main bulk of user-generated code.
It depends on your requirements. If the app you are developing is planned to be dynamic, then it is a good idea to do it the way it is described in the reference you provided. For example, you may create a class containing the method which will set the basic settings of the gridview, so on every page you may just call this method and pass to it the gridview as a parameter instead of repeating setting the grid properties on every page.

Best practices of building composite custom controls WPF

Can You tell me about subj?
For example I need to create new custom control that must be derived from datagrid and toolbar. And I want that new control to expose/propagate properties of base controls in order they to be accessed easily. The only way I know is deriving a class. Then descendant automatically gets all properties of ancestor. But multiple deriving in C# is prohibited, so I don't know how to expose properties and other behavior of second control... Styling and templating of such custom control is also needed.
Thanks!
In WPF inheritance is "out". ;O) Actually, it was complicated before WPF already, but with WPF you get various really powerful alternatives.
For the basic control I thing you'd better go with composition, create some usercontrol and make it contain a ToolBar and a DataGrid. You can then expose these as public properties, if you need to manipulate them from outside.
For special feature additions, attached properties are a very versatile mechanism.
Watching a window from windowsclient.net is a good place to start.
Make sure you understand dependency properties well.
Reading wpf blogs is my best guest for what to do then.

Resources