# Thursday, April 23, 2009

Silverlight Extensions

Comme vous le savez les 2 projets Silverlight Extensions et Silverlight Contrib sont en cours de fusion :

image

- Silverlight Extensions et Silverlight Contrib

- The Future of Silverlight Contrib

- MVPs Shine Silverlight Together at MVP Global Summit!

 

Pour l’occasion nous avons mis en place le nouveau site de Silverlight Extensions sous N2 CMS et le futur Blog de Silverlight Extensions sous BlogEngine.NET.

* En attendant que la fusion avance, n’oubliez pas d’aller sur les sites des deux projets Silverlight Extensions et Silverlight Contrib.

#    Comments [0] |
# Tuesday, April 21, 2009

France Télévisions – L’info en vidéo

Nouvelle version de l’application Silverlight L’info en vidéo.

Vous pouvez maintenant retrouver les vidéos des différentes émissions !

image

image

#    Comments [0] |

UCAYA Tour Next 7

::Au Sénégal::

Ucaya au sénégal

Encore le Sénégal :-)

#    Comments [0] |
# Friday, April 17, 2009

Silverlight Extensions et Silverlight Contrib

Comme nous vous le disions dans un précédent post et comme vous avez pu le voir sur les sites respectifs des deux projets, les 2 projets sont en cours de fusion. Le nom du projet résultant de cette fusion a été publié par Page Brooks sur un son blog. Un vote était organisé et c’est le nom silverlight extensions qui a remporté la majorité des voix. Retrouvez le post de Page Brooks

image[1] 

En attendant que la fusion avance, n’oubliez pas d’aller sur le site web des deux projets. slextensions et silverlight contrib

#    Comments [0] |
# Tuesday, April 14, 2009

Utilisation des behaviors pour localiser une application silverlight ou WPF

Il y a quelques temps déjà, j’ai ajouté à slextensions une classe permettant de localiser simplement une application à partir d’attachedproperty. La mode étant aux behaviors, j’ai rajouté une classe permettant cette localisation à la branche SL3 de slextensions. Cette classe possède 4 propriétés :

  • Key : la clé de la ressource provenant de votre ResourceManager
  • PropertyName : Le nom de la propriété à localiser
  • ResourceManagerKey : La clé avec laquelle retrouver le ResourceManager dans les ressources de l’application
  • ConvertXaml : Si la resource contient du Xaml, permet d’instancier ce xaml par le XamlReader.

L’utilisation est très simple voici un exemple de localisation d’un texte

            <TextBlock  >

                <i:Interaction.Behaviors>

                    <SLExtensions_Interactivity:Localize Key="WelcomeMessage" PropertyName="Text" ResourceManagerKey="MyResource" />

                </i:Interaction.Behaviors>

            </TextBlock>

et d’un ContentControl

            <ContentControl Height="121" Width="244" Canvas.Left="25" Canvas.Top="206" >

                <i:Interaction.Behaviors>

                    <SLExtensions_Interactivity:Localize Key="Welcome" PropertyName="Content" ResourceManagerKey="MyResource" ConvertXaml="True"/>

                </i:Interaction.Behaviors>

            </ContentControl>

Le code de la classe :

using System;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using Microsoft.Expression.Interactivity;

using System.Resources;

using System.Globalization;

using System.Windows.Markup;

using SLExtensions.Globalization;

 

namespace SLExtensions.Interactivity

{

    public class Localize : Behavior<FrameworkElement>

    {

 

        private string key;

 

        public string Key

        {

            get

            {

                return this.key;

            }

 

            set

            {

                if (this.key != value)

                {

                    this.key = value;

                    Refresh();

                }

            }

        }

 

        private bool convertXaml;

 

        public bool ConvertXaml

        {

            get

            {

                return this.convertXaml;

            }

 

            set

            {

                if (this.convertXaml != value)

                {

                    this.convertXaml = value;

                    Refresh();

                }

            }

        }

 

 

        private DependencyProperty dependencyProperty;

 

        private string propertyName;

 

        public string PropertyName

        {

            get

            {

                return this.propertyName;

            }

 

            set

            {

                if (this.propertyName != value)

                {

                    this.propertyName = value;

                    this.dependencyProperty = null;

                    Refresh();

                }

            }

        }

 

        private string resourceManagerKey;

 

        public string ResourceManagerKey

        {

            get

            {

                return this.resourceManagerKey;

            }

 

            set

            {

                if (this.resourceManagerKey != value)

                {

                    this.resourceManagerKey = value;

                }

            }

        }

 

        private void Refresh()

        {

            if (AssociatedObject == null

                || string.IsNullOrEmpty(propertyName)

                || string.IsNullOrEmpty(Key)

                || string.IsNullOrEmpty(ResourceManagerKey))

                return;

 

            if (dependencyProperty == null)

            {

                Type t = AssociatedObject.GetType();

                var field = t.GetField(propertyName + "Property", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);

                if (field != null)

                {

                    dependencyProperty = field.GetValue(null) as DependencyProperty;

                }

            }

 

            if (dependencyProperty != null

                && Application.Current != null)

            {

                ResourceManager resourceManager = null;

                var obj = Application.Current.Resources[ResourceManagerKey];

                if (obj is ResourceLoader)

                {

                    resourceManager = ((ResourceLoader)obj).GetResourceManager();

                }

                else

                {

                    resourceManager = obj as ResourceManager;

                }

 

                var resourceValue = resourceManager.GetObject(Key, CultureInfo.CurrentCulture);

                if (convertXaml && resourceValue is string)

                {                   

                    resourceValue = XamlReader.Load((string)resourceValue);

                }

                AssociatedObject.SetValue(dependencyProperty, resourceValue);

            }

        }

 

        protected override void OnAttached()

        {

            Refresh();

            base.OnAttached();

        }

 

        protected override void OnDetaching()

        {

            base.OnDetaching();

        }

    }

}

#    Comments [0] |

Concours du jeu des caméléons

Le concours du jeu des caméléons de bonne année 2009 s’est achevé le 31 mars.

ucayahny2009-RankingCapture

Notre grand vainqueur est originaire des Caraïbes. Pour l’occasion j’ai tenu à lui remettre son lot en main propre :-)

20090405-ucayahny2009-winner 20090405-ucayahny2009-winner (2)

20090405-ucayahny2009-winner (3) 20090405-ucayahny2009-winner (4)

20090405-ucayahny2009-winner (5)

Il a nettement plus la classe maintenant non ?! ;-)

Merci d’avoir participé !

#    Comments [2] |
# Tuesday, April 07, 2009

Les behavior en Silverlight 3 - MapState behavior

Exemple

Les behaviors introduits par blend 3 servent à étendre les fonctionnalités d’un contrôle à l’aide d’une nouvel élément que l’on peut poser graphiquement dans l’interface de blend. L’ajout de comportement n’est pas nouveau, c’est utilisé dans de nombreux projets (par exemple, la navigation deepzoom de slextensions est géré de cette manière), mais ici, l’intégration à blend est plutôt pratique et permet à un intégrateur de gérer du comportement sans écrire de code.

La classe MapState me permet de mapper l’état d’une propriété d’un contrôleur à un VisualState posé sur mon contrôle.

Ma classe contrôleur de test n’a rien de particulier. Voici sa définition.

    public class ApplicationController : INotifyPropertyChanged

    {

 

        #region INotifyPropertyChanged Members

 

        public event PropertyChangedEventHandler PropertyChanged;

 

        protected void OnPropertyChanged(string propertyName)

        {

            if (PropertyChanged != null)

            {

                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

            }

        }

 

        #endregion

 

        private TestStates state;

        public TestStates State

        {

            get { return state; }

            set

            {

                if (state != value)

                {

                    state = value;

                    OnPropertyChanged(StatePropertyName);

                }

            }

        }

 

        public const string StatePropertyName = "State";

 

    }

J’instancie ce contrôleur en l’injectant dans les ressources de l’application

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            x:Class="TestBehavior.App"

            xmlns:controllers="clr-namespace:TestBehavior.Controllers"

            >

    <Application.Resources>

        <controllers:ApplicationController x:Key="appController" />

    </Application.Resources>

</Application>

Je rajoute les références qui vont bien à mon projet

image

Je peux maintenant rajoute mon behavior à l’aide de blend

image

Je remplie le mapping et la source de mon behavior avec blend

image

Le morceau de code qui change l’état du contrôleur.

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            ApplicationController appController = Application.Current.Resources["appController"] as ApplicationController;

            appController.State = (TestStates) ((1 + (int)appController.State) % 3);

        }

Le code

Ma classe MapState hérite d’une classe ancêtre Behavior que vous trouverez dans l’assembly Microsoft.Expression.Interactivity.dll qui se trouve dans le dossier Libraries/Silverlight de Blend 3.

J’ai déclaré une propriété Source qui me sert à récupérer l’objet métier qui va me donner mon état et une propriété Property me donnant le nom de la propriété d’état. Ma source doit bien sur implémenter INotifyPropertyChanged pour que MapState soit notifiée du changement de propriété.
J’ai également une collection de MapStateMapping qui me fournisse un couple Valeur / VisualState.
Au changement de valeur sur ma source, je n’ai plus qu’à comparer par rapport aux valeurs de mapping est à déclancher le visualstate sur mon élément associé.

Le code complet de la classe :

namespace SLExtensions.Interactivity

{

    [ContentProperty("Mappings")]

    public class MapState : Behavior<FrameworkElement>

    {

        public MapState()

        {

            Mappings = new List<MapStateMapping>();

        }

 

        #region Source

 

        private PropertyInfo propertyInfo = null;

 

        public object Source

        {

            get

            {

                return (object)GetValue(SourceProperty);

            }

 

            set

            {

                SetValue(SourceProperty, value);

            }

        }

 

        /// <summary>

        /// Source depedency property.

        /// </summary>

        public static readonly DependencyProperty SourceProperty =

            DependencyProperty.Register(

                "Source",

                typeof(object),

                typeof(MapState),

                new PropertyMetadata((d, e) => ((MapState)d).OnSourceChanged((object)e.OldValue, (object)e.NewValue)));

 

        /// <summary>

        /// handles the SourceProperty changes.

        /// </summary>

        /// <param name="oldValue">The old value.</param>

        /// <param name="newValue">The new value.</param>

        private void OnSourceChanged(object oldValue, object newValue)

        {

            propertyInfo = null;

            INotifyPropertyChanged notifyingObject = oldValue as INotifyPropertyChanged;

            if (notifyingObject != null)

            {

                notifyingObject.PropertyChanged -= new PropertyChangedEventHandler(notifyingObject_PropertyChanged);

            }

            notifyingObject = newValue as INotifyPropertyChanged;

            if (notifyingObject != null)

            {

                notifyingObject.PropertyChanged += new PropertyChangedEventHandler(notifyingObject_PropertyChanged);

            }

            if (newValue != null && !string.IsNullOrEmpty(Property))

            {

                propertyInfo = newValue.GetType().GetProperty(Property);

            }

            RefreshState();

        }

 

        #endregion Source

 

        #region Property

 

        public string Property

        {

            get

            {

                return (string)GetValue(PropertyProperty);

            }

 

            set

            {

                SetValue(PropertyProperty, value);

            }

        }

 

        /// <summary>

        /// Property depedency property.

        /// </summary>

        public static readonly DependencyProperty PropertyProperty =

            DependencyProperty.Register(

                "Property",

                typeof(string),

                typeof(MapState),

                new PropertyMetadata((d, e) => ((MapState)d).OnPropertyChanged((string)e.OldValue, (string)e.NewValue)));

 

        /// <summary>

        /// handles the PropertyProperty changes.

        /// </summary>

        /// <param name="oldValue">The old value.</param>

        /// <param name="newValue">The new value.</param>

        private void OnPropertyChanged(string oldValue, string newValue)

        {

            if (Source == null)

                propertyInfo = null;

            else

                propertyInfo = Source.GetType().GetProperty(newValue);

 

            RefreshState();

        }

 

        #endregion Property

 

        public List<MapStateMapping> Mappings { get; private set; }

 

 

 

        void notifyingObject_PropertyChanged(object sender, PropertyChangedEventArgs e)

        {

            if(e.PropertyName == Property)

                RefreshState();

        }

 

        private void RefreshState()

        {

            // Do not refresh at desing time

            if (!HtmlPage.IsEnabled)

                return;

 

            if (Source != null && propertyInfo != null )

            {

                object propValue = propertyInfo.GetValue(Source, null);

 

                if (propValue == null)

                {

                    var nullMappings = from m in Mappings

                                       where m.Value == null

                                       || ((m.Value is string) && string.Empty.Equals(m.Value))

                                       select m.StateName;

 

                    try

                    {

                        SLExtensions.Controls.Animation.VisualState.GoToState(AssociatedObject, UseTransitions, nullMappings.ToArray());

                    }

                    catch

                    {

                    }

                }

                else

                {

                    MapStateMapping mapping = null;

                    foreach (var item in Mappings)

                    {

                        var value = item.Value;

                        if (value != null)

                        {

                            if (object.Equals(value, propValue))

                            {

                                mapping = item;

                                break;

                            }

 

                            if (propValue is IConvertible && value is IConvertible)

                            {

                                try

                                {

                                    var val2 = Convert.ChangeType(propValue, value.GetType(), CultureInfo.InvariantCulture);

                                    if (object.Equals(val2, value))

                                    {

                                        mapping = item;

                                        break;

                                    }

                                }

                                catch

                                {

                                }

 

                                try

                                {

                                    var val2 = Convert.ChangeType(value, propValue.GetType(), CultureInfo.InvariantCulture);

                                    if (object.Equals(val2, propValue))

                                    {

                                        mapping = item;

                                        break;

                                    }

                                }

                                catch

                                {

                                }

                            }

                        }

                    }

 

                    if (mapping != null)

                    {

                        try

                        {

                            SLExtensions.Controls.Animation.VisualState.GoToState(AssociatedObject, UseTransitions, mapping.StateName);

                        }

                        catch

                        {

                        }

                    }

                }

            }

        }

 

        /// <summary>

        ///

        /// </summary>

        public static readonly DependencyProperty UseTransitionsProperty = DependencyProperty.Register("UseTransitions", typeof(bool), typeof(MapState), new PropertyMetadata(true));

 

        /// <summary>

        /// True if transitions should be used for the state change.

        /// </summary>

        public bool UseTransitions

        {

            get { return (bool)this.GetValue(MapState.UseTransitionsProperty); }

            set { this.SetValue(MapState.UseTransitionsProperty, value); }

        }

 

        /// <summary>

        /// Hooks up necessary handlers for the state changes.

        /// </summary>

        protected override void OnAttached()

        {

            base.OnAttached();

 

            FrameworkElement element = this.AssociatedObject;

            if (element != null)

            {

                element.Loaded += new RoutedEventHandler(element_Loaded);

 

                RefreshState();

            }

            else

            {

                Dispatcher.BeginInvoke(delegate

                {

                    this.OnAttached();

                });

            }

        }

 

        void element_Loaded(object sender, RoutedEventArgs e)

        {

            RefreshState();

        }

    }

}

Les sources

En attendant de publier tout ça sur slextensions, vous pouvez télécharger le projet ici: 
Vous pouvez retrouver d’autres behavior sur le site de la gallery expression : http://gallery.expression.microsoft.com/

#    Comments [0] |
# Friday, April 03, 2009

silverlight 3 beta et silverlight 2 sur la même machine de dev

logo Travailler avec des versions beta de logiciels est parfois compliqué. Que faire avec les outils ? Est-ce que je les installe sur ma machine de développement, est-ce que je les installe sur une machine virtuelle ?

Vous trouverez ici : http://blogs.msdn.com/amyd/archive/2009/03/18/switching-from-silverlight-3-tools-to-silverlight-2-tools.aspx un petit script permettant de changer simplement la version des Silverlight tools utilisés par visual studio.

#    Comments [0] |
# Monday, March 23, 2009

MIX09

MIX09 à Las Vegas, nous y étions !

MIX09

De retour en france, voici une petite liste de liens en français dont les blogs des frenchies avec qui nous avons eu la chance de vivre cette magnifique expérience :

Pierre Lagarde : http://blogs.msdn.com/pierlag/

Dick Lantim : http://blogs.msdn.com/dicklant/

Christophe Lauer : http://blogs.msdn.com/clauer/

David Rousset : http://blogs.msdn.com/davrous/

LeMixer : http://lemixer.fr/

#    Comments [0] |
# Friday, March 13, 2009

Silverlight Contrib et Silverlight Extensions fusionnent

logo-slExt-ContrNous sommes fières d’annoncer aujourd’hui la fusion de Silverlight Contrib et Silverlight Extensions en un seul et unique projet ! Nous pensons que cette fusion apportera beaucoup de bénéfic es à la communauté. Cette combinaison permettra aux développeurs d’avoir un point unique pour rechercher des contrôles à intégrer dans leurs applications ainsi que pour en soumettre de nouveaux. Cette action réduira le temps passé dans chaque projet pour vous fournir des fonctionnalités équivalentes et nous permettra d’accélérer la cadence des releases.

Pendant la phase de consolidation du code, nous vous encourageons à nous soumettre vos retours ou problèmes à chaque projets. Nous fusionnerons les informations des deux projets lorsque le site commun sera ouvert et le nom final déterminé.

Quel nom allons-nous garder ? Cette décision vous appartient ! Vos votes détermineront le plus populaire. Assurez-vous que votre préférence soit prise en compte, votez ! Les votes seront acceptés jusqu’au 29 mars 2009 23:00 (GMT+1)

Nous vous tiendrons informé des évolutions sur chacun des blogs des 2 projets Silverlight Contrib et Silverlight Extensions.

Retrouvez ce post sur le site de Silverlight Contrib

Les équipes de slextensions et silverlight contrib.

#    Comments [0] |