0
votes

In my VSTO application-level word addin, I'm trying to add a Grid to a UserControl in order to make its layout coherent.

However, when I try to declare the grid, Visual Studio complains that the type or namespace "Grid" cannot be found. I solved this error by adding the PresentationFramework assembly as a project reference and importing System.Windows.Controls, but now I have an even bigger issue: Visual Studio complains that "UserControl" is an ambiguous reference between "System.Windows.Controls.UserControl" and "System.Windows.Forms.UserControl".

I checked the top of my .cs file and found it already was importing System.Windows.Forms by default and now, it is also importing System.Windows.Controls.

I'm wondering why the VSTO project defaulted to importing System.Windows.Forms in the first place instead of System.Windows.Controls and what the main difference is between the two namespaces because in my WPF application I use System.Windows.Controls. Thank you!

1

1 Answers

1
votes

From origin VSTO was a Forms based set of tooling, and XAML based UI option is only from later years. Obviously you still can use System.Windows.Forms and reference that in your XAML applications so when adding the XAML References there are some ambiguous items if both present (I always tend to run into the XAML and Forms MessageBox ambiguity interfaces) and you need to prefix the ambiguous items.

What I do is trying to be either full on the XAML side or decide to move to the Forms side.

Probably the VSTO, a somewhat older technology by now, project templating is based on the Forms libs to start with but you are free to move completely into the XAML world. My own solutions today are fully XAML based, but I fall back to Forms every now and then (doing a quick demo for instance).

So it is just a technology choice and VSTO is going back a long time so it started with Forms. Go with the new and shiny XAML technology if you like (I'm biased, I love that technology) or stick to the Forms technology. You can use them both.