0
votes

I'm new to XAML and likely not even thinking about this problem in the right way, but...

Basically I want a little XAML fragment that I can inject into various UserControls under some circumstances. The XAML just shows a small tag at the side of the control using a Border and a TextBlock.

It would be easy enough to cut and paste this to each control, but that feels clumsy and will be a pain any time I want to update it. Sure, I could do this at runtime in the control base class, but I would rather use the designer. I could make the tag a UserControl in its own right, but that sounds needlessly heavyweight too.

So is there some way of making little XAML fragments in the designer that I'm missing? I'm thinking there it would just have (in this case) the Border at the root of the XAML document.

This is for a Windows 8 store app using VS2013.

1
You could apply my answer here and just put it in your resource dictionary or generic.xaml or something so it can be reached as a StaticResource, then your multi-line becomes one line and you can re-use it all over the place easily and change it just one place when edits are necessary. - Chris W.
That's kind of what I want, but does that allow me to edit the XAML using the VS designer? - terriblememory
Of course, easiest route, wherever you have it on your view, right-click the ContentControl and choose "Edit Template->Edit Current" and it will open it up. - Chris W.

1 Answers

0
votes

Have you tried XAML Code Snippets? Tim Heuer has a nice post with examples here: http://timheuer.com/blog/archive/2013/07/08/xaml-code-snippets-for-visual-studio.aspx