Template 10 – Error CS0234 The type or namespace name ‘ApplicationInsights’ does not exist

Windows-Dev

Template 10 is set of Visual Studio templates for Windows 10 UWP C# and XAML applications. For those who are interested there is a whole course about Template 10 on the Microsoft Virtual Academy site.

Once you have installed Template 10 via NuGet you will find that your project fails to build with the following error:

Error CS0234 The type or namespace name ‘ApplicationInsights’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)

The solution is to add the following references to ApplicationInsights in project.json dependencies:

	"Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
	"Microsoft.ApplicationInsights": "1.0.0", 
	"Microsoft.ApplicationInsights.WindowsApps": "1.0.0",

You should then be able to build and run your Template 10 project.

The full project.json is as follows:

{
  "dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
	"Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
	"Microsoft.ApplicationInsights": "1.0.0", 
	"Microsoft.ApplicationInsights.WindowsApps": "1.0.0", 
    "Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
    "Newtonsoft.Json": "8.0.3",
    "Template10": "1.1.*"
  },
  "frameworks": {
    "uap10.0": {}
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

SourceStackoverflow

Windows 10 Insider Preview – Enabling Developer Mode

Windows-Dev

I installed Visual Studio Community Edition on the Windows 10 Insider Preview and got a pop-up message that told me that I needed to enable Developer Mode on my device.

The pop-up told me to go to the Settings to do this – but the option is not available there.

The solution is to open the Group Policy Editor and browse to:

Local Computer Policy, Administrative Templates, Windows Components, App Package Deployment

Select the Allows development of Windows Store apps and installing them from an integrated development environment (IDE) setting and set the state to Enabled.

win10-enable-dev-mode

Source: http://answers.microsoft.com/en-us/insider/forum/insider_wintp-insider_install/enable-developer-mode-for-windows-10/c85a90b0-056a-4e32-894e-d9e0dd2a54df

Windows Runtime – Special Characters in JSON (Parsed as HTML)

Windows-Dev

My app in progress uses a JSON data file that is parsed as HTML so that I can add bold and other useful HTML attributes to my data.

Until today, none of the special characters that I used within my bold tags presented any issues: *, ?, [ ], { }, !, >, >>

But, when I got the to the less than sign it was parsed as the opening of another HTML tag, and broke my lovely bold tags!

The solution was simple enough – simply encode the less than sign as I would in standard HTML, thus: <

So even though it works on WordPress, this is wrong:

<b><</b>

And this is right:

<b>&lt;</b>

Happy coding!

Windows Runtime – C# Send EMail from App

Windows-Dev

I’m working on my About page for a Windows Phone Runtime app and needed to be able to send an email for feedback or support issues.

Below is the code for my event handler in the code behind (AboutPage.cs):

        async private void Image_Email(object sender, TappedRoutedEventArgs e)
        {
            //Define email address to send to
            EmailRecipient sendTo = new EmailRecipient()
            {
                Address = "mail@domain.com"
            };

            //New email and define email subject
            EmailMessage mail = new EmailMessage();
            mail.Subject = "Linux Essentials - Feedback";

            //Add addressee to email
            mail.To.Add(sendTo);

            //Open share contact with email only
            await EmailManager.ShowComposeNewEmailAsync(mail);
        }

The XAML on my About page is simply an image with the Tapped event:

      <Image Source="Assets/Images/Mail.png"
             Height="64"
             Width="64"
             Margin="0,0,22,0"
             Tapped="Image_Email"/>

When defining a new email you can also specify the mail body text:

mail.Body = "this is the Body";

Source: http://dotnet.dzone.com/articles/how-send-mail-your-windows

Windows Runtime – C# Launch Hyperlink

Windows-Dev

I’m working on my About page for a Windows Phone Runtime app and needed to open a hyperlink in my code behind (AboutPage.cs).

Below is the code for my Tapped event handler:

        private void Image_Wordpress(object sender, TappedRoutedEventArgs e)
        {
            Launcher.LaunchUriAsync(new Uri("https://pricklytech.wordpress.com/"));
        }

The XAML on my About page is simply an image with the Tapped event:

      <Image Source="Assets/Images/Wordpress.png"
             Height="64"
             Width="64"
             Tapped="Image_Wordpress"/>

Source: http://stackoverflow.com/questions/12501174/opening-a-url-in-the-default-browser-in-a-windows-8-desktop-application

Windows Phone 8.1 Runtime – Forcing Light or Dark Theme

Windows8-Phone-Logo

In Windows Phone 8.1 Runtime apps we can set the theme for the app or for each page.

To set the them for the whole app add the highlighted code to App.xaml:

<Application
    x:Class="LinuxBasics.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:LinuxBasics"
    RequestedTheme="Dark">

For RequestedTheme you can choose light or dark. To set the theme per page use:

<Page x:Name="page"  RequestedTheme="Dark">

Sources: http://stackoverflow.com/questions/26478465/how-to-force-theme-in-windows-runtime-app