Preview WPF code-only controls in VS2010 - how?

Hope I can illustrate the problem using a lot of images. First of all, I was not a true XAML fan (Silverlight issues, Preview crashes, etc.)

Now, with VS2010, the situation has become better. There are many more things that I like best in the code, but I also need a preview in my VS.

So, take a look at the following control: it's really simple, a todo parts list. The first screenshot shows the control code, which is pretty good:

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

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

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

But in this case, I have an additional file that I do not need or do not need. So I had the idea of ​​moving init stuff inside the XAML control loop. For simplicity, I used simple elements. But they do not appear in the preview ...

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

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

Finally, I know that when creating user interfaces, I could use controls in other parts of my application. But I use the layout manager, PRISM, and many other things, so I just need a simple preview of some specific control that I created (without having to have a XAML wrapper file for each control)

Thanks for the help and sorry for the post structure, but I, although with the images, better understand ...

Chris

+4
source share
1 answer

Good,

I have found a way. I mostly fool VS by modifying XAML, but keeping the code binding to the file. This is the same as a shell solution, but without a dedicated class or file. I am using the "xaml-infront" file for preview.

This solution only works with clean code controls, I need to explore the mixed controls more (at least I think so ... but that's enough for me).

Please note that the code behind is NOT partial. It can be placed elsewhere, what I am doing here is mainly related only to file names and the "readability" of the visual studio.

See screenshots for explanation:

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

Some space to make reading easier

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

+1
source

Source: https://habr.com/ru/post/1308558/


All Articles