aprile 2010 Blog Posts
Some time ago I published onto CodePlex a new addin for Visual Studio 2010, named "XAML Code Snippets", which provides custom support for adding and exporting XAML code snippets in the WPF and Silverlight XAML code editor. Now I updated the source code in order to target VS 2010 RTM (also fixing some minor bugs).
You can find it here. Also the addin has now a page on the Visual Studio Gallery, available here, meaning that can be found via the Extension Manager dialog in Visual Studio. Your feedback would be really appreciated.
Alessandro
Provides support for adding XAML code snippets in the Visual Studio 2010 code editor for XAML in WPF and Silverlight projects.
The addin has been written in Visual Basic 2010 and actually targets Visual Studio 2010 RTM. It uses and creates classic .Snippet files for XML syntax. At runtime the XML markup is simply pasted as XAML in the code editor. You use it as follows:
1. to insert a code snippet, right click the code editor and select Insert XAML Code Snippet from the context menu:
2. in the appearing dialog select the folder containing your XML .Snippet files and then select...
If you use the My namespace from Visual Basic in WPF applications, especially the User object which allows accessing properties about the logged user, you might encounter a small problem. While in Windows Forms the following line returns the user name in the form of Domain\UserName:
Dim userName As String = My.User.Name
in WPF the same line of code returns an empty string. So, how can we solve this? there are basically two solutions. The first one is initializing My.User as follows:
My.User.InitializeWithWindowsUser()
'then invoke My.User.Name
Dim userName As String = My.User.Name
The second solution is utilizing the WindowsIdentity class as follows:
Dim userName As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name
If you like...