Simon Williams
Simon Williams

Reputation: 1046

Using behaviours and animations in Silverlight 4 with MVVM pattern

I have seen some great examples of using behaviours to trigger animations in Silverlight. It all seems really easy to do with Expression Blend by simply dragging behaviours onto controls on the screen. But what if my control isn't actually on the screen, since I am using a Listbox bound to a ViewModel in an MVVM pattern. The listbox items are created at runtime when things are added to a collection in my ViewModel. So how would I attach behaviours to those dynamically loaded listbox items?

Upvotes: 1

Views: 219

Answers (1)

Wouter Janssens
Wouter Janssens

Reputation: 1613

That it the great thing of MVVM. You can fill your properties of the ViewModel with DesignTime Data:

Example below of a property on the viewmodel that provides a list of strings and in design time it provides a list of 3 items:

    List<string> _myItems;
    public List<string> MyItems
    {
        get
        {
            if (DesignerProperties.IsInDesignTool)
                return new List<string>() { "item1", "item2", "item3" }; 
            return _myItems;
        }
        set
        {
            _myItems = value;
            NotifyPropertyChanged("MyItems");
        }
    }

Upvotes: 1

Related Questions