简体   繁体   中英

Preview of code-only WPF controls in VS2010 - how?

I hope I am able to illustrate the problem using a lot of images. First of all, I was no real fan of XAML (Silverlight issues, crashes in Preview, and so on...)

Now, with VS2010 the situation has become better. There are still a lot of things I like better in code, but I also want a preview in my VS.

So, take a look at the following control: It is really simple, a todo details list. The first screenshot shows the code of the control, pretty straighforward:

CodebasedControl http://img28.imageshack.us/img28/2263/invoicea49.png

There is no XAML, so obviously no preview. Of course, I could encapsulate it in another control, like shown in the next screenshot:

CodebasedControl http://img11.imageshack.us/img11/9515/invoicea48.png

But, in that case I have an additional file I do not want or need. So I had the idea to move the init stuff inside the contructor of a XAML control. For simplicity, I used simple elements. But they do not show up in the preview...

CodebasedControl http://img99.imageshack.us/img99/5547/invoicea47.png

CodebasedControl http://img512.imageshack.us/img512/9625/invoicea46.png

Finally, I know I could use the controls in other parts of my app when creating UIs. But I am using layout manager, PRISM and a lot of other stuff, so I just want an easy preview of some specific control I created (without having to have a XAML wrapper file for each control)

Thanks for help, and sorry for the post structure, but I though with images it is better to understand...

Chris

Ok,

I found a way. Basically I am tricking VS by changing the XAML, but keeping the code-behind linked to the file. It the same like the wrapper solution, but without having a dedicated extra class or file. I am using the "xaml-infront" file for preview.

This solution only works with pure code controls, I have to do more research for mixed controls (at least I think so.. but it is enough for me for now).

Please be aware, the code behind is NOT partial anymore. It could be placed anywhere else, what I am doing here is basically only related to file-names and visual studio "readability"..

See screenshots for explanation:

alt text http://img15.imageshack.us/img15/5456/invoicea50.png

Some space for easier reading

alt text http://img186.imageshack.us/img186/1545/invoicea51.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM