Monday, August 31, 2015

Beta testing Windows Phone 8.1 app in Windows 10 store

Problem:

Just have released a new version of an application which is hosted in Windows 10 store.
I was trying to set up some Beta testing which was quite straightforward in Windows 8 store.
The new store has a new process for Beta testing for Windows 10 devices.  This is not going to
help as Windows Phone 10 is still in Beta. 

How to Beta test Windows Phone 8.1 App?

Solution:

The key is too go to the Pricing and Availability page for your app.  Once there go to the  Distribution and Visibility section.  Set the cost to free and then expand the targeted distribution section.  Provide a list of users with live ids.  These will be your beta testers.  The app will only be visible to these users.

"The Windows Dev Center dashboard offers additional ways to distribute your app only to a targeted group of people via additional options in the Distribution and visibility section of the Pricing and availability page when submitting an app. You can use these options for testing or otherwise distributing your app. Note that these options do not work for all operating systems. Using promotional codes and hiding the app in the Store is recommended when you are testing your app on Windows 10 devices.

Targeted distribution to customers with specified email addresses
With this option, only the people whose email addresses (associated with their Microsoft accounts) that you enter in the box can download your app by using the direct link to its listing. You can find this link on the App identity page in the dashboard (use the URL for Windows Phone). No customers will be able to find the app by searching or browsing the Store, and even if they have the link to your app's listing, they won't be able to download the app unless they are using a Microsoft account associated with an email address that you provided when submitting this app."

Source

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/mt185377.aspx

Friday, August 28, 2015

Android SDK Tools (rev. 24.3.4) breaks Xamarin.Designer downgrade for Visual Studio

Problem:


Google has released a new version of Android SDK Tools (rev. 24.3.4). This version breaks the Xamarin.Android designer.

How to downgrade?

Downgrade steps

  1. Close ALL instances of Visual Studio and/or Xamarin Studio
  2. Locate the tools directory in the Android SDK path. One way to find the right directory is to open "Tools -> Open Android SDK Manager" in Xamarin Studio or "Tools -> Android -> Android SDK Manager" in Visual Studio. The tools subdirectory can be found within the "SDK Path" that is displayed at the top of the SDK Manager window.
  3. Delete the tools directory.
  4. Unzip the tools_r24.3.3*.zip file into the "SDK Path", creating a directory named "tools". Be careful not to create an extra outer "tools" directory when unzipping this file: the top-level "SDK path" should contain tools/android*, not tools/tools/android*.

Downgrade links

Windows
Mac
Source:
http://forums.xamarin.com/discussion/48408/warning-android-sdk-tools-rev-v24-3-4#latest

The publisher display name, $username$, specified in the package doesn't match the publisher name

Problem:

I was trying to publish latest upgrade to our app.  The Windows Phone version has just been completed.  No it is not a universal app yet.  That is coming.  This is a Windows Phone Silverlight 8.1 app.  I built the xap and went to deploy it to the store and got this weird error:

The publisher display name, $username$, specified in the package doesn't match the publisher name

Solution:

Turns out that Visual Studio can't update two very important files, package.appmanifest.xml and WMAppManifest.xml.  These have to be done by hand.  The MSDN article was not absolutely clear on where to go so I thought I would provide some cues. 

The MSDN article provides this handy table which required some careful reading to determine what was meant. 

Element or attribute to updateCorresponding value from your DashboardCorresponding field in Manifest Designer
Name attribute of the Identity element.Package identity name from the App info page.Package name on the Packaging tab.
DisplayName element.The reserved name for the app.Package display name on the Packaging tab.
Publisher attribute of the Identity element.Windows publisher name from the App info page.None.
Version attribute of the Identity element.Not applicable.Version on the Packaging tab.
PublisherDisplayName element.Publisher name from the Account summary page.Publisher display name on the Packaging tab.
Table 1

Step 1:

Go to the app page in the store
https://dev.windows.com/en-us/dashboard/apps/<Your App ID>/Identity

It provides the needed information for your app

Package/Identity/Name NameAppYour
Package/Identity/Publisher CN={App GUID}
Package/Properties/PublisherDisplayName Your App Name
Table 2

Step 2:

In Visual Studio, go to the release project in your solution and locate the file Package.appxmanifest.
Open this file and select the Packaging tab. 

Step 3:(Name attribute of the Identity element = Package/Identity/Name)

The package name listed should match should match the Package/Identity/Name in table 2.  If it does not then you will get an error when you try to publish to the store. 

Step 4:(PublisherDisplayName element = Package/Properties/PublisherDisplayName)

Ensure the Package Display name matches Package/Properties/PublisherDisplayName in table 2.

Step 5:(Publisher attribute of the Identity element = Package/Identity/Publisher.)

This last step requires you to leave Visual Studio and open the file Package.appxmanifest with notepad or text editor of your choice.  Visual Studio does not allow you to edit the last two fields which need to be done by hand.

Open the file and locate the identity element.  The publisher attribute should be set to the setting in
Package/Identity/Publisher.

<Identity Name="Your Package Name" Publisher="CN=Your Publisher ID" Version="1.0.0.0" />

Summary

Table 3 summarizes the changes and location for the elements.  Once I understood where the values were located I was able to load my Windows Phone app into the Windows Store without further errors.

Element or attribute to updateCorresponding value from your Identity Dashboard
Name attribute of the Identity element.Package/Identity/Name
DisplayName element.Select the Packaging tab in file Package.appxmanifest.
 Display name element allows you to change the value.
Publisher attribute of the Identity element.Package/Identity/Publisher
Version attribute of the Identity element.Select the Packaging tab in file WMAppManifest.xml. Version textbox allows you to change the value.
PublisherDisplayName element.Package/Properties/PublisherDisplayName
Table 3

Source

  1. https://msdn.microsoft.com/en-us/library/dn655122(d=printer,v=vs.105).aspx
  2. https://dev.windows.com/en-us/dashboard/apps/<Your App ID>/Identity

Thursday, August 27, 2015

Invalid package family name: Appname_q6srzhww6szzg (expected: Appname_e0kvyw5mrygy8)

Problem:

Trying to submit a Windows Phone Silverlight 8.1 app to the Windows Store and getting this error.
I was puzzled by the error so I started to play around with the Package.appxmanifest file.


Solution:

Listed with this error was also a related Invalid Publisher Name which was the underlying issue.  I had mistyped my publisher name.  This should be 36 character GUID and I had only 32 characters.
Once I had corrected the incorrect publisher name, the package family name was corrected.  This helped me understand that the package publisher GUID is being used to generate the unique id tacked onto the end of the package family name.

Needed to use the correct publisher name.  This is listed on your app identity page https://dev.windows.com/en-us/dashboard/apps/{App ID}/Identity

Source:

See my post coming later this week...

Wednesday, August 26, 2015

“Unable to connect to a phone. Make sure the Windows Phone IP over USB transport service is running”

Problem

Upgraded to Windows 10 and now VS will not connect to my windows phone over the usb cable!

Solution

  1. Restart IpOverUsbSvc service. (Control Panel > Administrative Tools > Services)
  2. Restart phone, and turn off Set Automatic in date+time.

Source

http://stackoverflow.com/questions/24153897/getting-error-unable-to-connect-to-a-phone-make-sure-the-windows-phone-ip-over

Tuesday, August 18, 2015

Windows Phone kill application everytime

Problem:


One issue I have with a windows application is application lifecycle.  I need to make sure that the app is terminated each time a user leaves the app.  The app can be Closed or deactivated.  The deactivation can leave the app running in the background.

 

Solution:

Add the following code block to the App.xaml.cs at the root level of your windows phone project.
Locate the method Application_Deactivated.

private void Application_Deactivated(object sender, ClosingEventArgs e)
{
      App.Current.Terminate();
}

MVVMCross - System.Reflection.TargetInvocationException was unhandled Message: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll

Problem:


I have my Windows phone project working great with my pcl core.  The MVVMCross libraries are working without issue.  What I have occurring is bug in the UI.  I open my app and run it just fine.  I then hit the windows button which puts the application into background.

When I reactivate the application it crashes with this error:

System.Reflection.TargetInvocationException was unhandled Message: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll

Solution:

I thought at first it would be an IoC error but it occurs to early for that.  I had to set a breakpoint in the app.xaml.cs in the Windows UI project.  The key was to set it at the Application_Activated event.
Otherwise the crash occurs and it goes straight to the dump.  I was able to walk through the issue until I hit the event RootFrame_NavigationFailed event.  Here I discovered the issue.  I took a look at the e.Exception (e is type NavigationFailedEventArgs).

e.Exception

{System.InvalidOperationException: No XAML found at the location /MainPage.xaml ...

So that was my issue!   The modifications to use MVVMCross means we do not need this page since the setup.cs file does the IoC transfer of the app at startup.  This transfer pushes control down to the PCL layer. My oversight was that the WMAppManifest.xml file has a navigation Page attribute which was set too MainPage.xaml.


NOTE to MVVMCross Users:
What I neglected to do was what Stuart Lodge points out in his N+5 series.  The key event RootFrameOnNavigation in App.xaml.cs needs to handle the IoC redirection.  I did not do this in my Windows project.  Thus the event should include the following code

Fix 1:
private void RootFrameOnNavigating(object sender, NavigatingCancelEventArgs args)
{
args.Cancel = true;
RootFrame.Navigating -= RootFrameOnNavigating;
RootFrame.Dispatcher.BeginInvoke(() => { Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.ViewModels.IMvxAppStart>().Start(); });
}

Fix 2:
I continued to have problems due to some code I dropped into the InitializePhoneApplication event.
It says don't touch very clearly!  I did anyway and this was also causing load time issues.  I eliminated my extra code and the method should look like this:

// Do not add any additional code to this method
private void InitializePhoneApplication()
{

            if (phoneApplicationInitialized)

                return;
            // Create the frame but don't set it as RootVisual yet; this allows the splash
            // screen to remain active until the application is ready to render.
            RootFrame = new PhoneApplicationFrame();
            RootFrame.Navigated += CompleteInitializePhoneApplication;

            // Handle navigation failures
            RootFrame.NavigationFailed += RootFrame_NavigationFailed;

            // Ensure we don't initialize again
            phoneApplicationInitialized = true;
}


Now that I have done both of these steps I no longer receive the error.

Source:
  1. https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/blob/master/N-05-MultiPage/MultiPage.Phone/App.xaml.cs
  2. http://mvvmcross.blogspot.com/

Monday, August 17, 2015

Using Conditional Compilation Symbols

Problem:
I have a Portable Change Library (PCL) as core project in a mobile MVVMCross solution.  The code supports Anrdroid, Windows Phone and iPhone.  I have been trying to compile specific code for use with Windows Phone.  I had the code working but was unsure how to proceed to support the other 2 UIs which use the PCL.

Solution:
I read John Atten's excellent article on how to leverage Conditional Compilation on Visual Studio.
I defined the tag - MVVMCross_WP8 and added that to the build profile for Windows Phone.  I added the tag in the properties > build for the PCL core.


Source:
http://typecastexception.com/post/2012/08/18/Visual-Studio-Use-Conditional-Compilation-to-Control-Runtime-Settings-for-Different-Deployment-Scenarios.aspx

MVVMCross Core solution throws error - Unhandled managed exception

Problem:

I just completed the Windows Phone UI project for an MVVMCross solution.  The core project is used by iPhone and Windows Phone UI.  Upon completion of testing for WP, I decided to run a few tests against iPhone which I had completed earlier.  I was immediately confronted with an error -

"An Unhandled exception occurred"

The Xamarin log shows the error occurring at load time.  The compiler built out the bits.  The attempt to run in debug did reveal some more interesting leads. 

[3641:134567] Unhandled managed exception: Could not load file or assembly 'Windows' or one of its dependencies.  The system cannot find the file specified.  (System.IO.FileNotFoundException)

I continued to play around with the changes I had made to the Core PCL.  Then I found the issue.

Solution:

In the course of building the Windows Phone project I used the LongListSelector. This Windows Phone control has several dependcies which are specific to Windows Phone.  The Core PCL included some code which depended on the library Microsoft.Phone.dll.  This reference is not compatible with the Monotouch framework.  My code worked fine when I compiled to Windows Phone but as soon as I tried to run the exe to Monotouch I raised the error. 

My solution was to surround the code with conditional compilation commands

#if USE_MVVMCROSS_WP8

....

#endif

Source:
http://typecastexception.com/post/2012/08/18/Visual-Studio-Use-Conditional-Compilation-to-Control-Runtime-Settings-for-Different-Deployment-Scenarios.aspx

Thursday, August 13, 2015

Flush dns settings for Windows

Problem:

Brought my development box back onto the disconnected LAN.  I have the mac box running dns.
I connected my PC but it refused to acquire a new dns.  How to force the DNS to refresh?

Solution:
Ensure that the DNS service is still running on the Mac.  Mine had stopped which was the issue.
Once I restarted the Mac, I did the following commands:

cmd prompt (Admin)

ipconfig /flushdns

ipconfig /release

ipconfig /renew



Source:

http://www.techmynd.com/how-to-flush-dns-get-new-dynamic-ip/

Monday, August 10, 2015

How to center the hint in a WP8 Toolkit PhoneTextBox


Problem:
I'm using a WP8 toolkit PhoneTextBox control. I'd like the hint to be set top and left. The following code should work but it is like the HintCustom Style is begin ignored!

<toolkit:PhoneTextBox Name="textLongUrl" TextWrapping="Wrap" InputScope="Url" Height="150" MaxLength="250" DisplayedMaxLength="250" LengthIndicatorVisible="True" FontSize="20" Hint="Type or paste URL" HintStyle="{StaticResource HintCustomStyle}" ActionIcon="Assets\Images\icon-button-32.png" ActionIconTapped="textLongUrl_ActionIconTapped" KeyDown="textLongUrl_KeyDown" />


And here's the hint style I'm using:
<Style TargetType="ContentControl" x:Key="HintCustomStyle">
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="FontSize" Value="36"/>
</Style>


Solution:

The issue is the toolkit itself.  The PhoneTextBox is predefined and that is what needs to overridden.  The Hint style I had created was being overridded each time the screen loaded by the PhoneTextBox.
This means that I needed to override the PhoneTextBox itself.

Do the following:

Open the project in blend and Right click on the PhoneTextBox and select Style > Edit a copy to edit the template. Find the Border named "HintBorder" and expand it to see "HintContent" and "ContentElement" ContentControls. "HintBorder" is the one you want. Select it and from the property panel set the HorizontalAlignment to Left and VerticalAlignment to Top, that should do it. Your Hint Text is vertically aligned to the top and left adjusted. I also added some Fontsize specifics for my app.




Source:
http://stackoverflow.com/questions/20778159/how-to-center-the-hint-in-a-wp8-toolkit-phonetextbox

Mulitline Xaml button in Windows Phone

Problem:
I was trying to get a button to include multiple lines.  I tried using the declarative syntax in the button

<Button
Content="My Main Title \n Subtitle"/>

This did not work since this is going to render without the formatting implied inline.

Solution:
Really straight forward just add the textbox control into the button control and move on.

<Button
 Command="{Binding MVVMControl}"
 Name="MyFabulousButton">

<TextBlock
TextAlignment="Center"
TextWrapping="Wrap">
First Line
<Linebreak/>
Second Line
</TextBlock>
</Button>






Source
http://stackoverflow.com/questions/1449276/multline-text-in-a-wpf-button

Friday, August 7, 2015

Change Grid/Button Background color through MVVM pattern in Windows Phone

Problem:


Having completed an iPhone app using an MVVMCross core backend.  I need to create the windows phone version UI for the backend.  The iPhone app uses the SegmentControl on a view.  The iPhone app works great and seemlessly with the core.  Now windows phone does not have a segement control per se.  You could simply use a hub/tiles or panorama control templates.  The customer however is very enamored of  the look an feel of the Segment Control.  So it was off too Xaml and blend to build out a similar control.  This I accomplished pretty quickly. 

The issue is the binding to the modelview.  Their is no command property on the grid; however the button control does.  So how to get the interaction to bind with the model view?  Fortunately we have the iValueConverter in the UI layer.  This allows us to bind to properties in the xaml controls.  This combined with model view can allow us to get the functionality to match the segmentcontrol.

Solution:


modelview

private Cirrious.MvvmCross.ViewModels.MvxCommand _myCommand
public ICommand MyCommand
{
             get
            {
                  _myCommand = _myCommand ?? new Cirrious.MvvmCross.ViewModels.MvxCommand(DoMyCommand);
                   return _myCommand;
            }

}

private void DoMyCommand()
{
             ISActive = true;
}


private bool _isActive;

public bool ISActive
{
         get
         { return _isActive;}
         set { _isActive = value;
             RaisePropertyChanged()) => ISActive);
        }

}

view (xaml)

xmlns:phone="clr-namespace:Microsoft.Phone.Controls..."
xmlns:local="clr-namespace:MyNamespace"

<phone:PhoneApplicationPage.Resources>
<local:BrushColorConverter x:Key="ColorConverter" />
</phone:PhoneApplicationPage.Resources>
......

<Grid
Background={Binding ISActive Converter={StaticResource ColorConverter}}
....>
<Button
Background={Binding ISActive Converter={StaticResource ColorConverter}}
Command="{Binding MyCommand}"
.....
/>

</Grid>


(BrushColorConverter.cs (separate class file) in UI project)
 public class ColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
        {
            return new SolidColorBrush(Colors.Transparent);
        }
        return System.Convert.ToBoolean(value) ?
            new SolidColorBrush(Colors.Red)
          : new SolidColorBrush(Colors.Transparent);
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}




Source:
  1. http://stackoverflow.com/questions/7329812/change-button-background-color-through-mvvm-pattern-in-wpf
  2. http://www.codeproject.com/Articles/758656/Use-Converters-in-your-Windows-Phone-Apps

Wednesday, August 5, 2015

Windows Phone disable status bar

Problem:
Trying to fix a problem on a Windows Phone Silverlight 8.1 app today.  The app starts with a splash screen and do to some extra processing it has an extended screen which simply displays the same screen again.  The issue arises when the splash screen which the OS handles switches over to the first view which also displays the same splash screen image.  Due to the status bar displaying on the first screen the image shifts down.  This leads the image dropping down vice staying in place.  The transition from needs to be smooth without any resizing of the image.  The solution seems to be simply to hide the status bar on that screen.  But how to do it?

Solution:

Windows Phone 8 / Windows Phone 8/8.1 Silverlight


Code behind in ExtendedSplashScreenView.xaml.cs:

public partial class ExtendedSplashScreenView(): MvxPhonePage
{
  InitializeComponent();
  Loaded += MainPage_Loaded;
}

private void MainPage_Loaded(object sender, RoutedEventArgs events)
{
  SystemTray.IsVisible = false;
}


Windows Phone 8.1

Code behind in ExtendedSplashScreenView.xaml.cs:

public partial class ExtendedSplashScreenView(): MvxPhonePage

{
  // Get the Status bar for the Current Window.
  Windows.UI.ViewManagement.StatusBar statusBar =     Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
  // Hides the status bar
  await statusBar.HideAsync();
}


Source:
1.) Windows Phone 8 / Silverlight
  • http://stackoverflow.com/questions/6674627/how-to-hide-the-status-bar-in-wp7-silverlight
2.) Windows Phone 8.1
  • http://blogs.msdn.com/b/johnkenn/archive/2014/04/16/hiding-the-status-bar-in-windows-phone-8-1-apps-or-not.aspx
  •  http://developerpublish.com/how-to-hide-status-bar-in-windows-phone-8-1-xaml-app/
  •  http://blogs.msdn.com/b/amar/archive/2014/05/12/status-bar-in-windows-phone-8-1.aspx