Visual Studio 2010 Service Pack 1 Beta

The first Service Pack for Visual Studio 2010 has just been announced.

In it are some interesting features:

  • Silverlight 4 Tools for Visual Studio 2010 are included(with a few updates to RIA Services)
  • Performance Wizard for Silverlight
  • IntelliTrace F5 for 64 bit and SharePoint projects finally
  • Unit Testing on .NET 3.5
  • VB Compiler runtime switch
  • new Help Viewer

Currently, the Service Pack comes as Beta, but it has a “go live” license. This means it is already recommended to use it for production related work.

The Service Pack will be available for public on Thursday: here

If you have a MSDN Subscription, you may download it right now: here

Watch the Silverlight Firestarter event with us!

 

 

Silverlight is dead??? I don’t think so!

Microsoft is spending Silverlight a whole day. Holding this great live event in Redmond and streamed online around the globe.

When:

Thursday, December 02, 2010 9:00 AM
Pacific Time (US & Canada)

See agenda and register for free: here

 

This event is a part of Microsoft’s Firestarter series, which is dedicated to improve skills in different Microsoft technologies.

 

If you live in Switzerland, you have an additional opportunity to enjoy this event. The newly formed Silverlight User Group of Switzerland, presents a public viewing.

We will start at 17:15 (Swiss time) on the 2nd of December in Microsoft Switzerland (Richtistrasse 3, 8304 Wallisellen ZH).

On the program:

  • Welcome greetings.
  • Short explanation of what the SLUGS (Silverlight User Group of Switzerland) is and how we hope to grow with your help.
  • Live streaming of the Silverlight Firestarter keynote by Scott Guthrie.
  • Discussion, pizza.

This should be a fun evening, and we hope to see many of you at this occasion! Please register here if you want to attend!

 

We are looking forward to watching this cool event with you!

Windows Phone UI Design and Interaction Guide V2 available

 

The Windows Phone OS 7 User Interface (UI) is based on a design that is
named Metro.

Metro design interfaces embody harmonious, functional, and attractive visual elements that encourage playful exploration so that the user feels a sense of wonder and excitement.

To develop Application for the Windows Phone 7 by following the Metro design, it is essential to read to new version of the Design guidelines. In it you will learn how to give the user of your application the experience, that your app is a part and belonging to the phone.

download: Windows Phone UI Design and Interaction Guide

Windows Phone Developer Tools Beta released

A new and fresh Windows Phone Developer Tools release has arrived. Download here

This probably will be the last version before the final release at the end of this summer.

Everything you need to develop nice phone applications is in this download:

  • Visual Studio 2010 Express for Windows Phone – a new free, express edition of Visual Studio 2010
  • Express Blend for Windows Phone – a new free, edition of Blend focused on Windows Phone 7 development
  • Silverlight for Windows Phone 7
  • XNA Game Studio for Windows Phone 7

Integrated with the development tools is a phone emulator that enables you to easily develop and test Windows Phone 7 applications on your laptop or desktop machine – without requiring a phone device.  It is hardware accelerated, supports multi-touch events on multi-touch capable monitors, and provides a really easy way to debug and try out your phone applications.

There are a lot of changes since the last release (April CTP), so better check out the Release notes here

Binding EventArgs to Command

While using the  ModelViewViewModel Pattern, people running in different kind of problems.

One common problem is the handling of the UI Events in the ViewModel without to write any code in the code behind file.

In my example I want to get the position of the mouse while it moves.

My approach for a solution is:

 

1. Write a Behavior to grab  the EventArgs of its associated object

public class ExtendedInvokeCommandAction : TriggerAction<FrameworkElement>
    {
        public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ExtendedInvokeCommandAction), new PropertyMetadata(null, CommandChangedCallback));
        public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(ExtendedInvokeCommandAction), new PropertyMetadata(null, CommandParameterChangedCallback));

        private static void CommandParameterChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var invokeCommand = d as ExtendedInvokeCommandAction;
            if (invokeCommand != null)
                invokeCommand.SetValue(CommandParameterProperty, e.NewValue);
        }

        private static void CommandChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var invokeCommand = d as ExtendedInvokeCommandAction;
            if (invokeCommand != null)
                invokeCommand.SetValue(CommandProperty, e.NewValue);
        }

        protected override void Invoke(object parameter)
        {
            if (this.Command == null)
                return;

            if (this.Command.CanExecute(parameter))
            {
                var commandParameter = new ExtendedCommandParameter(parameter as EventArgs, this.AssociatedObject,
                                                                    GetValue(CommandParameterProperty));
                this.Command.Execute(commandParameter);
            }
        }

        #region public properties

        public object CommandParameter
        {
            get { return GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

        public ICommand Command
        {
            get { return GetValue(CommandProperty) as ICommand; }
            set { SetValue(CommandParameterProperty, value); }
        }

        #endregion
    }

2. Write a class to store the Information about the event and the object

public class ExtendedCommandParameter
    {
        public ExtendedCommandParameter(EventArgs eventArgs, FrameworkElement sender, object parameter)
        {
            EventArgs = eventArgs;
            Sender = sender;
            Parameter = parameter;
        }

        public EventArgs EventArgs { get; private set; }
        public FrameworkElement Sender { get; private set; }
        public object Parameter { get; private set; }
    }

3. Attach the Behavior to any object of the View

In my sample I attached my ExtendedInvokeCommandAction to a Rectangle

image

 

4. Bind this Behavior to a Command in the ViewModel and choose an Event on which the Command will be invoked.

In my sample below I used the MouseMove Event and bound this to  the MouseMoved Command, which I defined in the ViewModel. Additionally you can bind any object to the Command as the CommandParameter, if you need it for some reasons.

I bound the View (name=”userControl”) in my sample(not needed).

image

 

 

 

 

 

 

 

 

 

 


<Rectangle Fill="#FF9B9BC5" Height="200" Stroke="Black" Width="200">
    		<i:Interaction.Triggers>
    			<i:EventTrigger EventName="MouseMove">
    				<local:ExtendedInvokeCommandAction
					Command="{Binding MouseMoved}"
					CommandParameter="{Binding ElementName=userControl}"/>
    			</i:EventTrigger>
    		</i:Interaction.Triggers>
    	</Rectangle>

 

5. Handle the event in the ViewModel.

public class MainPageViewModel : INotifyPropertyChanged
    {
        public MainPageViewModel()
        {
            MouseMoved = new MainPageCommand(this); //initialize the Command
        }

        //gets the position of the mouse
        private void OnMouseMove(ExtendedCommandParameter commandParameter)
        {
            MouseEventArgs eventArgs;

            //cast the EventArgs to the type you expect, according to the event you handle
            //f.e. MouseMove Event  gets you MouseEventArgs
            //     Click Event gets you RoutedEventArgs
            if (commandParameter.EventArgs.GetType() == typeof(MouseEventArgs))
            {
                eventArgs = commandParameter.EventArgs as MouseEventArgs;
                if (commandParameter.Parameter != null)
                {
                    var view = commandParameter.Parameter as UIElement;
                    MousePosition = eventArgs.GetPosition(view).ToString();
                }
            }
        }

        public MainPageCommand MouseMoved { get; set; }
        private string _mousePosition;
        public string MousePosition
        {
            get { return _mousePosition; }
            set { _mousePosition = value; OnPropertyChanged("MousePosition"); }
        }

        #region INotifyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        internal void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region command class

        public class MainPageCommand : ICommand
        {
            public MainPageCommand(MainPageViewModel view)
            {
                _view = view;
            }

            private MainPageViewModel _view;

            #region ICommand Members

            public bool CanExecute(object parameter)
            {
                return true;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                //call the method to handle the event
                _view.OnMouseMove(parameter as ExtendedCommandParameter);
            }

            #endregion

        }
    #endregion

    }

 

You can use this Behavior for every EventArgs you need. Just bind it to a Command and in the code of the Command handling cast the EventArgs field of the ExtendedCommandParameter object to the EventArgs you expect.

Download Visual Studio 2010 Solution

PostSharp 2.0 CTP 5 supports Silverlight

 

A new release of PostSharp 2.0 has been announced. This time with support for Silverlight 3 + 4 and Windows Phone 7.

We had to wait a long time for this, since the last version only supported Silverlight 2.

More information and download here:

http://www.sharpcrafters.com/blog/post/Announcing-PostSharp-20-CTP-5.aspx

Close Out Of Browser Application

 

In a previous post I explained how to close an Silverlight OOB Application using Com Automation Factory.

With the final release of Silverlight 4 it it not necessary to go this way any longer. There is a better and more easy approach for this.

Use this snippet to close an OOB App:

if (Application.Current.IsRunningOutOfBrowser && Application.Current.HasElevatedPermissions)        

     Application.Current.MainWindow.Close();

 

Enrico

Silverlight 4 released

Finally, the waiting time is over.
The final Silverlight 4 runtime and development tools for Visual Studio 2010 has been released yesterday.

Download here:

Silverlight 4 Windows Developer Runtime
Silverlight 4 Tools RC2 for Visual Studio 2010
This tools will work with the Visual Studio 2010 RTM (released on Monday).

By the way, now it is exactly 3 years since Microsoft introduced the name Silverlight. The time is really running.
If you take a look at the first Silverlight version, you couldn’t do that much with it. And now we have Silverlight 4 and we can write amazing applications with it.
The Silverlight team at Microsoft did a really great job and I can’t wait to get the next version in my hands. I expect this to happen this year.

Enjoy Silverlight 4

Silverlight 4 Launch Keynote

The Silverlight 4 Launch Keynote is just over and the Silverlight 4 Final Release will be available on Thursday this week.

If you have seen the the MIX10 Silverlight Keynote before and now the Launch Keynote, you propably have experienced kind of a Déjà vu sometimes. At least I have felt like this.
Nethertheless, Silverlight 4 and it’s features is awesome.

In the Keynote they also showed a presentation of Silverlight for embedded devices, such as connected TV’s, Blu-ray Disc players and other connected consumer electronics devices. I really like to have the User Interface of my TV build with Silverlight. And they said this will be the full Silverlight (without any changes).

So, "Silverlight everywhere" comes closer.

Silverlight COM+ Automation Tips #5 – Get all installed Fonts

Text elements in Silverlight can use a subset of the fonts on the client computer. If you wanna use and change a font programmatically(without embedding it), you have to know which fonts are installed on the client.

Be aware, you can only use Silverlight supported fonts with the current Silverlight version. Check out the list of supported fonts:
http://msdn.microsoft.com/en-us/library/cc189010(VS.95).aspx#fonts_in_silverlight)

With this snippet, you’ll get a List of installed fonts in Out-Of-Browser Mode.

Code:

var directoryname = @"C:\Windows\Fonts";
var fontList = new List();
dynamic winObject = null;
if (AutomationFactory.IsAvailable) //only in Trusted Out Of Browser Mode
{

winObject = AutomationFactory.CreateObject("Scripting.FileSystemObject");
dynamic mainFolder = winObject.GetFolder(directoryname);

foreach (dynamic file in mainFolder.Files)
{
fontList.Add(file.Name);
}
}

Return top