Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 142, comments - 0, trackbacks - 0

My Links

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2012

Order my book about VB 2012 on Amazon My book "Visual Basic 2012 Unleashed" is available. Click the cover!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

campusMVP.NET - Tutored online training for Microsoft developers

Follow me on Twitter!

Messenger me!


CyberInstaller Beta Tester

Download CIS 2008!!

CodePlex download Download my open-source projects from CodePlex!

Search the blog



Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

giovedì 3 ottobre 2013

A new app for Windows Phone 8 built with VB: Where are my Items?

It's been a long time since my last post in this blog. As you might know, I run an Italian community about Visual Basic so writing in two different languages concurrently can be hard, especially when you also author books about programming, such as Visual Basic 2012 Unleashed

About Visual Basic, I use it everyday not only for building business apps and for authoring learning materials, I also use it for building apps for Windows Phone.

I have recently published a new app, called Where are my Items? (download here). The goal of the app is saving the location of your objects, so that you will never forget where they are; you can also add a picture and backup data on your SkyDrive.

So, why am I telling you this? Because it's the first time I implement localization in multiple languages and that I use in-app purchases APIs. Of course, I did test in-app purchase so it works Since it has been the first time I used some features, I'd like to ask your feedback. If you have some free minutes, please download the app and give me some feedback. I appreciate it.

Secondly, I'd like to give a mention to Telerik and its great RadControls suite for Windows Phone. I've used Telerik controls for animated tiles and zoom-image in the app and it was fun.

Final note: there is an update of the app that is waiting to pass certification. This update will fix some issues with the light theme of the phone and, most importantly, will be more consistent with the English language, so the title is going to be replaced with Where are my Things?

Thanks for your feedback!

Alessandro

posted @ giovedì 3 ottobre 2013 12:51 | Feedback (0) | Filed Under [ Visual Basic Silverlight/Windows Phone Visual Studio 2012 ]

martedì 21 maggio 2013

Deploying IntelliSense code snippets for Visual Studio 2012 with VSIX packages

Back in Visual Studio 2005, Microsoft introduced reusable code snippets that can be picked up in the code editor with IntelliSense support. Something like this:

Code Snippets are XML files with .snippet extension based on a specific schema. Rather than typing manually your XML files, a good idea is using a snippet editor. There are a lot of snippet editors available for free, I personally use the Snippet Designer editor which is integrated in the IDE. With an editor like this, you simply write or copy-paste code and provide the appropriate metadata information. The editor is responsible for producing well-formed XML files that can be correctly recognized by Visual Studio.

I will not cover creating code snippets here, I will instead show how to package snippets for easy deployment.

Once you have your snippets, you might want to use them in the code editor or to share them with other developers. Code snippets are stored inside language-specific folders, such as C:\Program Files (x86)\Microsoft Visual Studio 11.0\VB\Snippets\1033. Also, Visual Studio provides the My Code Snippets folders where users can save snippets without being administrators.

In the previous editions of Visual Studio, you could package a number of snippet files (plus add-ins, macros, item/project templates, controls) inside a .Vsi installer. Then, the Visual Studio Content Installer tool helped users install contents into the appropriate location.

Even though .Vsi packages are still supported, Visual Studio 2012's extensibility relies on the VSIX file format, which provides a better customer experience. For this reason, sharing reusable code snippets should be done with a VSIX package.

Assuming you have a number of snippets ready and that you already installed the Visual Studio 2012 SDK, the first thing you need to do is creating a new, empty VSIX project:

In Solution Explorer, add a new folder to the project where you will store snippets. The name of the folder is very important, because it will be also the name of the group of snippets inside the code editor. Add all the .snippet files you want to deploy to other developers:

As you can see in the figure, it is very important to remember to set the Build Action, Copy to Output Directory, and Include in VSIX properties as shown, otherwise snippets will not be included in the package.

The next step is adding a package definition file, with .pkgdef extension. To add one, you can simply use the text file template. The package definition file will tell the installer where to install code snippets. I am using Visual Basic code snippets, so I'm going to use the following syntax:

[$RootKey$\Languages\CodeExpansions\Basic\Paths]
"DelSoleVBSnippets"="$PackageFolder$"

What the code does, is finding the registry key that contains the collection of directories for VB code snippets on the target machine. To this collection, a new path is added with the custom key specified on the second line. Supported language identifiers are Basic, CSharp, SQL, HTML, XML, C++, and JavaScript. You can check out the MSDN documentation for additional strings in the pkgdef file.

Don't forget to set the file properties as you already did for snippets. The next step is making a manual edit to the extension manifest. In Solution Explorer, right click the source.extension.vsixmanifest file and choose to open it with the XML internal editor, finally add the following node before the closing file tag:

  <Assets>
    <Asset Type="Microsoft.VisualStudio.VsPackage" Path="Snippets\DelSoleVBSnippets.pkgdef" />
  </Assets>

Close the XML editor and re-open the manifest with its designer. Set the extension's metadata (publisher, license, images) but make sure you do not change the asset added manually. You are done.

You can now debug your extension in the experimental instance of Visual Studio by simply pressing F5. When ready, switch to the Release configuration and build the solution. You will find the redistributable .Vsix package under Bin\Release as usual. This package can be easily published to the Visual Studio Gallery for easy deployment through the Extension Manager in Visual Studio.

Note: if you plan to install your snippets to a non-default location, you might need to create a snippet index file. Check out this page in the MSDN documentation.

Enjoy your code snippets!

Alessandro

posted @ martedì 21 maggio 2013 07:40 | Feedback (0) | Filed Under [ Visual Studio 2012 ]

giovedì 14 marzo 2013

Retrieving RSS feeds for Twitter and Facebook

You might need to analyze RSS feeds from different pages in order to get information and latest news from a channel. Facebook and Twitter are probably the most interesting, but there's no easy specific API.

Fortunately it is possible to retrieve the RSS feed 2.0, that is XML, in a pretty easy way. The following URL allows retrieving the RSS feed of a Facebook page (not user profile):

https://www.facebook.com/feeds/page.php?id=pageidnumber&format=rss20

Where pageidnumber is the id of the desired page. For instance, the Facebook address for my VB community in Italy is the following:

https://www.facebook.com/feeds/page.php?id=295804250449780&format=rss20

About Twitter, you can retrieve a feed like this:

https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=username

Where username is the account name of the person you are following. For instance, this is the RSS feed for the profile of my Italian VB community:

https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=vbtipsandtricks

You might find this useful 

Alessandro

posted @ giovedì 14 marzo 2013 10:32 | Feedback (0) | Filed Under [ Misc ]

Windows Phone: picking up contacts in code

In Windows Phone apps, you can easily pick up contacts from the contact list in code. You simply need to use a chooser called Microsoft.Phone.Tasks.AddressChooserTask.

You define an instance:

    Private contattoSelezionato As String
 
    Dim WithEvents addressChooser As AddressChooserTask
 
    Public Sub New()
        InitializeComponent()
        Me.addressChooser = New AddressChooserTask
     End Sub

Then you invoke Show to start the chooser:

addressChooser.Show()

To determine the returned contact, you handle the Completed event and you read the value only if the user has confirmed her choice (the TaskResult.OK value from the TaskResult enum):

    Private Sub addressChooser_Completed(sender As Object, e As AddressResultHandles addressChooser.Completed
        If e.TaskResult = TaskResult.OK Then
            Me.contattoSelezionato = e.DisplayName
        End If
    End Sub

Other than the DisplayName you can also retrieve the Address , which is actually the value that determines the difference between contacts with the same name or between elements belonging to the same contact.

Alessandro

posted @ giovedì 14 marzo 2013 10:25 | Feedback (0) | Filed Under [ Silverlight/Windows Phone ]

A VS2012 extension to use the WinRT APIs in desktop apps

Anyone who has ever built for Windows 8 and the Windows Runtime probably wondered how it is possible to use WinRT in desktop applications.

Even though with some limitations, this is possible and requires some manual steps so that a project can reference Windows 8's libraries.

Lucian Wischik  has published an interesting extension for Visual Studio 2012, which adds a Console app project template which is ready to take advantage of WinRT.

Such an extension is available from the Visual Studio Gallery at this address, where you will also find hints for the usage.

Lucian has also published an article on CodeProject, where he provides detailed information about this scenario.

Remember that som APIs from WinRT cannot be used on the desktop for privacy and security reasons, especially those related to some devices and that work in a sandboxed environment.

Alessandro

posted @ giovedì 14 marzo 2013 10:20 | Feedback (0) | Filed Under [ Windows 8 & WinRT Visual Studio 2012 ]

WinRT: ho to solve if ListView and GridView lose their way

In a Windows Store App I've been working on, I had to face a particular problem. It is a problem that can randomly occur with the GridView and ListView controls and it probably depends on the DataTemplate you use.

Consider the following GridView:

                <GridView Name="MyView" ItemsSource="{Binding}" Margin="0,15,0,0" HorizontalAlignment="Left">
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <!-- custom DataTemplate -->
                        </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>

In this page I have this object; then I navigate to a secondary page. From the secondary page, I navigate back to the page where I have the GridView.

As a result, instead of showing items horizontally (as required), the control shows them vertically losing the original orientation.

I searched on the Internet but the only one taling about this problem is a guy at Microsoft, who provides a possible solution in this blog post. Unfortunately that solution did not work for me, so what I did is changing the template of the panel for the view. In this case I used a StackPanel. This works well for me because I have a few items and I don't need virtualization. In code:

                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>

In this way, everything worked correctly. In conclusion, if you face this problem remember to work on the ItemsPanelTemplate.

Alessandro

posted @ giovedì 14 marzo 2013 10:14 | Feedback (0) | Filed Under [ Windows 8 & WinRT ]

Playing media contents in loop with the MediaElement control

The MediaElement control is used to play media contents in Technologies like WPF, Silverlight, WinRT and Windows Phone.

You might have the need to play a content forever, with a loop. A very easy way to accomplish this is Handling the MediaEnded and restart from there.

For example, we declare a boolean variable to store the loop state (enabled/disabled):

Private isLoop As Boolean = False

This can be useful if we associate the state of the loop to a button, which is just responsible to change its value:

    Private Sub LoopButton_Click(sender As Object, e As EventArgs)
        isLoop = Not isLoop
    End Sub

Somewhere else we'll start playing the content; the important thing is how we handle the event, like in the following example:

    Private Sub Media1_MediaEnded(sender As Object, e As RoutedEventArgsHandles Media1.MediaEnded
        If isLoop = True Then
            Me.Media1.Position = New TimeSpan(0)
            Me.Media1.Play()
        End If
    End Sub

Basically the code first checks if the loop state is active, then it moves the position back to zero and restarts playing.

Alessandro

posted @ giovedì 14 marzo 2013 10:04 | Feedback (0) | Filed Under [ Silverlight/Windows Phone Windows Presentation Foundation Windows 8 & WinRT ]

My first eBook: "Hidden WPF"

A few days ago, we have released my first eBook called "Hidden WPF: Secrets for creating great applications in WPF":

Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation

Published by InformIT (the online division of my publisher SAMS/Pearson), this is a different publication. It's a very small book, 99 pages, produced and thought for mobile devices. Here you will find tons of tips & tricks, suggestions, and real world implementations that I collected in my daily work, building applications with Windows Presentation Foundation.

Price is $ 7,99. You will find many info about working with PDF and XPS documents, suggestions to get the most out of the Visual Studio IDE with WPF, enhancing your debugging experience, improving the user interface performance, common requirements (e.g. ComboBox controls with lookup tables), descriptions of Productivity tools either free or paid, that you might have probably missed.

I'm aware that WPF has been definitely become very popular in the developer community Worldwide, so probably this publication can bring you some value. After all, we do not have to forget that WPF is the premiere technology about building apps for the Desktop, despite HTML5, the Web, and the apps for Windows 8.

Alessandro

posted @ giovedì 14 marzo 2013 09:58 | Feedback (0) | Filed Under [ Windows Presentation Foundation ]

Powered by:
Powered By Subtext Powered By ASP.NET