johnvisiomvp

Life with Visio and other Microsoft Toys!

Archive for the ‘XAML’ Category

UWP Samples generate hundred of errors?

with one comment

For the past few months I have had problems trying to run any of the Windows 10 UWP samples. Each attempt resulted in hundreds of errors.  Yesterday, thanks to Colin Melia and a little Google spelunking I may have found the issue and the solution.

The Googling turned up https://github.com/Microsoft/Windows-universal-samples/issues/182 which indicates the same issues and that the problem may be with one of the references, Microsoft.NetCore.UniversalWindowsPlatform. Since I have been having issues, I did a clean install and installed the Windows 10 SDK. The issue appears to be that the samples were created with the 5.0 version of that file, but the clean install used 5.1. So when trying to open the samples, the reference could not resolve.

The solution was to open the project, in the Solution Explorer, right click reference and chose Manage NuGet Packages… Select Microsoft.NetCore.UniversalWindowsPlatform and select Update. I was able to do a Clean Project and Run.

No more errors!

Hopefully this will work for others.

Remember, if your solution contains more than one project, you probably will have to do this for each project.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

April 17, 2016 at 4:21 pm

WP7 Multilingual AppBar.

with one comment

The current phone app I am working on is based around a pivot and to get the most out of the pivot I want to use a different appbar for each pivot item. Luckily, Microsoft has a good article on how to do it.

How to use different app bars in a single Pivot control for Windows Phone

Unfortunately, the article has a few problems. The main ones deal with a need to know. This is a pivot and this article suggests placing the appbar in App.xaml. This is a pivot and only the page with the pivot needs to know about it or cares. This also means the background code will be in App.xaml.cs which complicates things. Since most of my apps have been multilingual, the solution did not handle the binding required for the resource file.

So the solution was to take the idea and move it to the page that had the pivot. This meant changing the xaml code from using Application.Resource to phone:PhoneApplicationPage.Resources and use throwaway values for the text. The SelectionChanged method of the pivot would take care of adding the correct text. Since I like to have optional menu items and there is no way to hide menu items, I left that up to the code behind and removed any references to the appbar menu from the xaml code. The resulting SelectionChanged method looked like.

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch (((Pivot)sender).SelectedIndex)
{
case 1:
ApplicationBar = ((ApplicationBar)Resources["AppBar1"]);
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = AppResources.AppBar1a;
((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Text = AppResources.AppBar1b;
((ApplicationBarIconButton)ApplicationBar.Buttons[2]).Text = AppResources.AppBar1c;
((ApplicationBarIconButton)ApplicationBar.Buttons[3]).Text = AppResources.AppBar1d;
break;
case 2:
ApplicationBar = ((ApplicationBar)Resources["AppBar2"]);
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = AppResources.AppBar2a;
((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Text = AppResources.AppBar2b;
((ApplicationBarIconButton)ApplicationBar.Buttons[2]).Text = AppResources.AppBar2c;
break;
default:
ApplicationBar = ((ApplicationBar)Resources["AppBar0"]);
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = AppResources.AppBar0a;
((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Text = AppResources.AppBar0b;
break;
}
ApplicationBar.MenuItems.Clear();
ApplicationBar.IsMenuEnabled = true;

ApplicationBarMenuItem appBarMenuItem;
appBarMenuItem = new ApplicationBarMenuItem(AppResources.lblLive);
appBarMenuItem.Click += new EventHandler(Click_Live);
ApplicationBar.MenuItems.Add(appBarMenuItem);
if (App.isTrial)
{
appBarMenuItem = new ApplicationBarMenuItem(AppResources.lblBuyNow);
appBarMenuItem.Click += new EventHandler(Click_Buy);
ApplicationBar.MenuItems.Add(appBarMenuItem);
}
if (App.EdomDog)
{
appBarMenuItem = new ApplicationBarMenuItem(AppResources.lblEdomDog);
appBarMenuItem.Click += new EventHandler(Click_EdomDog);
ApplicationBar.MenuItems.Add(appBarMenuItem);
}
}

Now, as the app evolves, I have an easy framework to build the appbars on. The code is contained to the page that needs it, it supports multiple languages and it supports optional items.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

January 15, 2014 at 9:42 am

WP7/8 Mystery of the screen bounce?

with one comment

I have been working on a new app that required more screen real estate than the phone provided.  All my attempts to get a canvas inside a standard ScrollViewer ended in having the unusual effect that I could not scroll to the bottom or far right. As soon as I took my finger off the screen, the screen would bounce inwards. A little online search indicated that the problem was known, but was not repeatable. Since there are so many unknown variables in a XAML solution, I can not claim that this is the definitive answer.

The thing that helped resolve the issue was changing the  background to something other than black. It is not easy to see the edges of a black shape on a black background. When I did this, I noticed several shapes that extended beyond the canvas and when I tried to scroll to the edge, it snapped back to the canvas that was now visible. I then made sure that I let the program reset the page size to include the wayward shapes. Now I have a WP7/8 app that has a canvas that can be bigger than the screen size and will scroll to the edge correctly.

Now on to finish the app and add it to my collection.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

February 6, 2013 at 2:34 pm