johnvisiomvp

Life with Visio and other Microsoft Toys!

Universal Apps – Sort of?

leave a comment »

In WP8, I can set up a view and use a few SortDescriptions and I have view several my data in a sorted format. Not so with a universal app. The answer I received from the forums is that:

Universal apps are based on WinRT, not Silverlight. As you can see in the relevant APIs:

Windows.UI.XAML.Data.CollectionViewSource does not have a SortDescriptions property.

System.Windows.Data.CollectionViewSource does have a SortDescriptions property.

So, it appears UAs have taken a step back from phone apps.  Sorting, something that should be standard, does not exists.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

July 25, 2014 at 5:48 pm

Universal Apps – TextBox

leave a comment »

Though not specifically for Universal Apps, the TextBox control has been nicely enhanced. In the past, if we wanted a header, we had to add a TextBlock before the TextBox. This meant coordination was required every time the TextBox had to be repositioned. Now the TextBox control includes a Header parameter. If you are not entirely happy with how the Header appears, There is a HeaderTemplate.  Just include

<TextBox.HeaderTemplate><DataTemplate>Text=”Header”</DataTemplate></TextBox.HeaderTemplate>

within the TextBox control. Now you can format it to your hearts content and it will move with the TextBox if it is repositioned.

Another new feature is that you can include a watermark within the TextBox as a placeholder. So if the TextBox is empty, it displays some default  text.  This is handled by the PlaceholderText parameter.

Of course, those that know me know that I like making everything multilingual. These parameters do not disappoint, they also support multilingual text. Just add a x:Uid to the TextBox and include rows in the resource file referencing that Uid. So, if the Uid is Num1, your resource file should include Num1.Header and Num1.PlaceholderText. If you do add the HeaderTemplate, it can use an x:Uid within the TextBox or a different x:Uid within the HeaderTemplate.

No matter how many times I do it, I still need to double check the difference between TextBox and TextBlock.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

July 9, 2014 at 8:31 pm

Universal Apps – Starting from Windows Phone 7

leave a comment »

So, in other posts I have mentioned what is new as far as Multilingual support and Navigation is concerned. Now it is time to point out other differences.

For those lovers of Blend, it is now gone. Okay, it is still there, but it has lost its’ place on the Project menu. Now you have to right click a xaml file to invoke it. It is definitely a tool to be used.

Isolated Storage seems to have gone. You now use
var localSettings =Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["MyFirstVar"] = “Hello Windows”;

if(localSettings.Values.ContainsKey(“MyFirstVar”)
Object value = localSettings.Values["MyFirstVar"];
or
var roamingSettings =Windows.Storage.ApplicationData.Current.RoamingSettings;
if(roamingSettings.Values.ContainsKey(“MyFirstVar”)
Object Value = roamingSettings.Values["MyFirstVar"];

Signatures on routines have changed. EventArgs has been replaced by RoutedEventArg.

OrientationChanged has now gone. So has Split if you peeked at Windows 8 development. Use the SizeChanged keyword on the XAML page. Use Windows.Current.Bounds.Width to get the widths value. you can use
ApplicationViewOrientation winOrientation = ApplicationView.GetForCurrentView().Orientation;
if (winOrientation == ApplicationViewOrientation.Landscape)
{
// Landscape layouts
}
else if (winOrientation == ApplicationViewOrientation.Portrait)
{
// Portrait layouts
}

For keyhandling, replace System.Windows.Input.Key.D0 with Windows.System.VirtualKey.Number0.

 

So how do you do convert a WP7 app to a universal app? Since there is no update button, you will have to do it manually. Unlike WP7/WP8 development, app names have to be unique, so the first step is to reserve the name. The next step is to create a Universal App with that name. As Andy points out in , the UA templates do not fully support navigation, so delete MainPage.xaml and create a new one based on Basic Page.

Within the Windows and Phone folders, create a strings folder as mentioned in the article on the Multilingual toolkit. The first version of you app may be unilingual, but by setting the ground work, adding new languages should be relatively easy. The hard part will be creating all the blarney and screen shots for the marketplace. Luckily, the Multilingual Toolkit can help (It is designed to help handle translations and not all string translatons will be INSIDE the app.).

Within the Shared folder, create a new folder called Old and place the XAML, CS and image files of the WP7 or WP8 project in it. Along with any other data that is needed by the project. This will be your working folder and the items will be removed from the folder as you convert. You did remember to do a backup of the original project? ;-)

Within the Windows and the Phone folders, create new XAML with the names used in the original project. Copy the main part of the original XAML to the new XAML files, ignoring the declaration section. Within the Shared folder create a class for the C# code behind and name it with the same name as the code behind. Place the content of the code behind within it ignoring the Usings,  Anything with Phone in the name will have to be replaced, so the Usings can be recreated (or in some cases pointed to new locations).

 

This is a work in progress, so I will be updating this post in the future.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

June 22, 2014 at 3:35 pm

Universal Apps – Multilingual Toolkit

leave a comment »

I fell in love with the Multilingual Toolkit when it was first introduced and found it very useful to add multiple languages to my apps. The only down side was that the submission process increased with each language. Even so, the Toolkit was useful in translating the text that is submitted with the app. All I had to do was add extra strings to the project, have them translations and then use the translations in the submission.

The XLF files use an industry standard for translators, so it is a very useful way to communicate with translators. The translator may have his own application for handling the XLF file, but the Toolkit does come with a useful app that anyone can use to do the translation. Unfortunately, the first release seemed to indicate that you had to install Visual Studio, the current version still seems to be a part of Visual Studio.

Of course, that familiarity caused problems. When you add languages in WP7 or WP8, the toolkit would automatically add the resource file (resx) and the XLF file for that language. With 8.1, only the XLF file is added. Of course, correcting that mistake is a mistake, only the resource file for the default language is needed. If you add the missing resource files, you will get a cryptic error message about duplication.

Rather than AppResources.resx, 8.1 uses resw files and the name is string/EN/Resources.resw. Converting from resx to resw is just a matter of renaming the extension, but I prefer to just copy all the strings and paste. I have yet to try it, but it should be possible to add the language to the filename as was done in WP7 / WP8.

With 8.1 the C# code for using strings from the resource file is to add

var loader = new Windows.ApplicationModel.Resources.ResourceLoader();

and
ErrorBlock.Text = loader.GetString(“ErrorCode01″)

In the xaml it is a matter of

x:Uid="Help"

to the textblock or button. This will overwrite the content of the Text or Content parameter, but they should be left in for editing. I tend to add an x to the end of the test. Unlike in WP7 and WP8, Visual Studio does not show the resource string in the editor. So the overwritten string are useful for determining the look and feel while editing.

Also  there is no XML that shows the languages being used, so the task of removing a language is just a matter of deleting the appropriate XLF file.

Another interesting thing is that the UIC can change several attributes. So for one use of a UIC, you can change the text and the width for a textblock. In the resource file it would be Help.Text and Help.Width.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Universal Apps – Navigation

leave a comment »

Unlike the navigation on Windows Phone 7, the navigation is a bit more complex in a Universal App, but luckily, Microsoft has provided some helpers. To add the helpers, you need to create the page with a Basic rather than a Blank page. You will be told that you are missing components and do you want to add them. Accept and the navigation components will be added. One key point that MVP Andy Wigley mentioned in an MVA course on Building Apps for Windows Phone 8.1 JumpStart is that the Blank default MainPage is created with a Blank page rather than a Blank Page. So you need to delete the MainPage and create a new one from a Basic page.

For some reason, I used cut & paste to merge a WP7 project into a UA project and somehow lost the name of the page (It should be pageRoot). Trying to work out what went wrong was not easy. For the most part, the process seemed easy. Create a skeleton app with the name you want, delete MainPage and replace with a new one based on Basic page and cut and paste the code. Ignore the declaration section of the old cold and just copy over the content of the Grid.

The NavigationService.Navigate are replaced with Frame.Navigate(typeof(NextPage));

Most of the code in the cs files are placed in classes using the same name in the Project.Shared folder. So there should be a MainPage.xaml.cs in that folder when you are done. The code in the xaml files will be in the Windows and duplicated in the Phone folders. This is where most of the differences of the Windows and Phone versions of the app will appear.

Andy Wigley’s JumpStart course on MVA is a good start.

Next time languages.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

June 7, 2014 at 4:54 pm

Universal Apps – One App to Rule Them All?

leave a comment »

Microsoft is helping developers by merging the two main platforms (Windows & Phone), but unfortunately, if you do a search on Universal App you will get a lot of information about another company trying to combine their platforms.

In the second update to Visual Studio 2013, they added supported for Windows Phone 8.1 and Universal Apps. So far it is not a complete merger because Windows and the Phones still have differences in their capabilities and API calls, but they are heading towards a single development model. The Universal App model is a blend of Phone and Windows development, taking the best from each.

Here is a good link to get started.

http://Building universal Windows apps for all Windows devices

One good link on that page is to a set of samples:
Universal Windows app samples

Unfortunately, though there are short descriptions of each sample, it is hard to figure out the framework they use. It seems someone at Microsoft forgot that these are provided as learning examples and are trying to impress with cleverness. Sorry, that does not work. Writing simple and clear examples is the way to go.

The Universal Apps are created with three sections: Windows, Phone and Shared and the structure is easy to navigate. Though not implemented, adding the Multilingual Toolkit is just a matter of enabling it in Visual Studio and adding the appropriate languages.

So, it is now time to abandon phone development and concentrate on Universal Apps.

Here are some more links:
http://msdn.microsoft.com/en-us/library/windows/apps/dn609832.aspx

Using Visual Studio to build Universal XAML Apps

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

April 28, 2014 at 3:55 pm

Multilingual Toolkit does not work?

with one comment

After looking at my download stats last week, I decided to upgrade all my WP7 apps to WP8 and continue developing from the there. The stats should that it was no longer worth the effort of maintaining a WP7 version of the code. The existing programs would remain in the marketplace, but not be updated.

For most of my apps, the upgrade went fine, but one app seemed to have an issue with being multilingual. (If I was going to upgrade my apps, I might as well give the users a bit more than a WP8 version of what they had.) Unlike a new WP8 app, upgrading to multilingual was not an easy task. A Resource directory had to be added and several strategic pieces of code had to be added to handle the resource files. For some reason I had missed something in upgrading this one app. No matter what language you set the phone to, the app was in English.

So, I abandoned trying to tweak the app to get it to work and just created a new WP8 app. Turning on the Multilingual Toolkit, adding a few target languages was all that was needed to create a generic multilingual phone app. Then came the task of actually making the app useful.

  • All the files for the other pages of the original app and any extra files were copied to the directory of the new project.
  • All the extra references including the Phone Toolkit from were added.
  • The extra code from the original App.xaml and Mainpage.xaml were added to the project.
  • The records from the original AppResources.resx were copied to the new AppResources.resx
  • The project was compiled
  • The XLF files were selected and the translations were machine generated
  • One more compile

And it worked. Still not sure what exactly was wrong with the upgraded file, but I did notice that the new App.XAML did contain some resource handling code that was not in the upgraded version. Adding the missing code did not help, but it did indicate that there was something else missing.

So yes, I could have spent more time tracking down what was wrong, but it did show that starting with a clean program was a better choice. I would never know if there was something waiting to bite me.

In WP8, the process of adding multiple languages is simple

  • Install the Multilingual Toolkit
  • Turn it on
  • Populate AppResources with your phrases.
  • Find all the reference for Text= and Content=
  • Change the fixed text to use
    Text=”{Binding Path=LocalizedResources.thestring, Source={StaticResource LocalizedStrings}}” in the XAML and AppResources.thestring in the C# code
  • Compile
  • Select the languages
  • Select all the XLF files and generate a machine translation. You can improve the translations later.
  • Compile

You will now have a multilingual app.

Enjoy.

John…

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

March 19, 2014 at 12:52 pm

Follow

Get every new post delivered to your Inbox.

Join 339 other followers