DCSIMG
Microsoft Open House Summary - WPF 4 and Blend 4 - Essential WPF

Microsoft Open House Summary - WPF 4 and Blend 4

To all of you who participated in my WPF 4 and Blend 4 lecture at Microsoft Raanana today, it was my pleasure.

I hope that you enjoyed and learned one or two things new about WPF.

 

You can download the presentation and demo code from here.

Hope to see you soon.

Published Sunday, November 14, 2010 4:54 PM by Tomer Shamam

Comments

# re: Microsoft Open House Summary - WPF 4 and Blend 4

Wednesday, November 17, 2010 3:53 PM by Saragani

Hi,

We have a problem and we are hoping that you have a solution or suggestion.

We want to use MEF in out project. The "plugins" will actually be elements with different types.

To make a small example, let's assume that out program is a Paint software, and our elements derives from an abstract class called Shape.

We would like to add more and more shapes to the Paint software just by adding more DLLs to the MEF/Catalog directory.

For each shape a button will be created, so we can click on it in order to draw a new shape.

Right now, if we have defined several types of ViewModels, we could have defined in our view that the default view for a ViewModel_X is View_X.

For example:

<UserControl.Resources>

       <DataTemplate DataType="{x:Type viewModels:ViewModel_X}">

           <views:View_X/>

       </DataTemplate>

</UserControl.Resources>

Now we don't have this option any more.

We would like to have a ViewModel that contains the list of the currently painted shapes and then the Main View would draw the shapes.

This is off course just an example, but here are the questions:

1) How to achieve the Binding to the list of shapes?

My guess will be creating an ItemsControl that uses a Panel like Canvas.

Is there any other solution?

2) How can we have the Model, ViewModel and View of each Shape in the DLLs and have the MainUI draw the shapes other than doing for example RectangleViewModel.ToString() ??

I was thinking of having the XAML/UserControl in the MetaData. Is this the right way?

If not, what other solutions do I have?

3) As you probably knows, MEF creates 1 instance of each the object in Catalog. This means that I can create only 1 Shape of each kind.

Right now, the solution we are thinking of is to have the Shape have a function like "CreateNew" that will return a new instance of the object.

Any other solution??

Thanks

# re: Microsoft Open House Summary - WPF 4 and Blend 4

Thursday, November 18, 2010 9:15 AM by Saragani

Hi, why wasn't my previous comment/question approved?

# re: Microsoft Open House Summary - WPF 4 and Blend 4

Thursday, November 18, 2010 9:04 PM by Tomer Shamam

Hi Saragani,

Your previous comment has been filtered as spam somehow, but I resurrected it ;)

As for your questions:

1. You should have a collection of ViewModel in your "canvas" view-model with ImportMany MEF attribute on it. Just bind this property as your source of the ItemsContol.ItemsSource you should have in your “canvas” view.

2. You should create a triad in each DLL for each shape of course, and you should provide kind of service, for example: IResourceService which has AddResource method which merges your view’s DataTeplate with the application. Then WPF will use this resource DataTemplate automatically. There are other ways too…

3. In such case you should Export a shape factory class, not the shape itself. You should have a Create method of course which creates the shape ViewModel.

It’s funny because I’ve architected a similar project with MEF and stuff one month ago… 

Please feel free to ask should you want me to consult.

Tomer

# re: Microsoft Open House Summary - WPF 4 and Blend 4

Thursday, November 18, 2010 10:50 PM by Saragani

Ok, thanks. :-)

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above:
Powered by Community Server (Commercial Edition), by Telligent Systems