wpf

XamlResource.com

Since today XamlResource.com is officially in beta. Its purpose is to create a platform to find and share resources for Silverlight and WPF, resources in the form of Xaml. Have a look around and if you run into issues, please let us know at xaml@hotmail.nl.

 

Beta 1:

In Beta 1 only a few of the final categories are supported:

  • Colors; Resources of type SolidColorBrush
  • Gradients; Resources of type GradientBrush
  • Color sets; 2 to 5 resources of type SolidColorBrush
  • Vectors; Resources of type StreamGeometry

This list will be extended with Styles, Themes, Templates and Shaders.

 

Future plans:

  • Adding tags and searching by them.
  • Access to the site from within Expression Blend
  • Client side validation of entered xaml using Silverlight
  • Automatic generation of preview image
  • Download multiple resources at once in one ResourceDictionary
  • An rss feed for news items

If you have requests for features you can let them know by using http://XamlResource.uservoice.com. For anything else, send an email to xaml@hotmail.nl.

To keep up to date, follow us at http://twitter.com/XamlResource

 

Logo

MVVM Project and Item Templates

Intro

This is the first in a series of small articles about what is new in Silverlight 4 and Expression Blend 4. The series is build around a open source demo application SilverAmp which is available on http://SilverAmp.CodePlex.com.

 

MVVM Project and Item Templates

Expression Blend has got a new project template to get started with a Model-View-ViewModel project  easily. The template provides you with a View and a ViewModel bound together. It also adds the ViewModel to the SampleData of your project. It is available for both Silverlight and Wpf.

clip_image002To get going, start a new project in Expression Blend and select Silverlight DataBound Application from the Silverlight project type. In this case I named the project DemoTest1.

clip_image004

The solution now contains several folders:

  • SampleData; which contains a data to show in Blend
  • ViewModels; starts with one file, MainViewModel.cs
  • Views; containing MainView.xaml with codebehind used for binding with the MainViewModel class.
  • and your regular App.xaml and MainPage.xaml

The MainViewModel class contains a sample property and a sample method. Both the property and the method are used in the MainView control. The MainView control is a regular UserControl and is placed in the MainPage.

You can continue on building your applicaition by adding your own properties and methods to the ViewModel and adding controls to the View.

Adding Views with ViewModels is very easy too. The guys at Microsoft where nice enough to add a new Item template too: a UserControl with ViewModel. If you add this new item to the root of your solution it will add the .xaml file to the views folder and a .cs file to the ViewModels folder.

image

Conclusion

The databound Application project type is a great to get your MVVM based project started. It also functions a great source of information about how to connect it all together.

 

Monitoring routed events in WPF

A few days ago I wanted to monitor all routed events fired in my application. Because I am running an XBAP application inside a browser windows, Snoop wasn’t very helpful (it usually is). Because all routed events are basically the same, you can handle them all with one singe event handler. Using the EventManger it is possible to get all routed events and register a class handler for every one of them.

The code below is a stripped down version of the code I’ve got implemented. When loaded, it gets all events. Than it loops to them and assigns a handler to them. It writes every event that is caught to the console. If you are using commands, you may way to filter them out, because very often the CanExecute and PreviewCanExecute events are raised on every command registered.

 

 

public partial class myUserControl: UserControl
{
 
  public  myUserControl()
  {
    InitializeComponent();
    Loaded += myUserControlLoaded
  }
  
  void myUserControlLoaded(object sender, RoutedEventArgs e)
  {
    var events = EventManager.GetRoutedEvents();
    foreach (var routedEvent in events)
    {
      EventManager.RegisterClassHandler(typeof(myUserControl),
                          routedEvent, new RoutedEventHandler(handler));
    }
  }
 
  internal static void handler(object sender, RoutedEventArgs e)
  {
    Console.WriteLine(e.OriginalSource + "=>" + e.RoutedEvent);
  }
}
Shout it
Tags van Technorati: ,
dotNed blogger
kick it on DotNetKicks.com

 

 

Twitter