How can I create a Windows Control Library project in Visual Studio? - winforms

i was trying to complete a tutorial on custom controls and all of the tutorials that ive found say that you have to choose a project template called "windows control library". I don't have that template as an option! I am using VS2010 professional. Any ideas?

The "Windows Control Library" project template is used to quickly get started creating custom controls for use in Windows Forms (WinForms) applications. It creates a project that is automatically populated with the necessary references and files.
To create a new project of this type, you first have to pick one of the .NET languages—it doesn't matter which—either C#, VB.NET or C++/CLI.
Then, select the "Windows" category to narrow down the scope of the project types that are listed.
Finally, select the project type called "Windows Forms Control Library".

Related

How do I add XAML windows to a .Net Core "WPF Application"?

In Visual Studio 2019, if I create a new "WPF Application" using .Net Core (top in the screenshot below) it will create a project for me that does in fact include a working XAML setup. However, there is no way that I can find to add a new XAML window through the VS interface. Right-clicking on a folder, choosing Add and then Window (WPF) just gives you the codebehind, no XAML anywhere.
If instead I create a new "WPF App (.NET Framework)" (bottom in the screenshot) It creates a similar project but I can in fact add XAML windows via right-click and selecting Add as above, including the relevant codebehind.
What gives? If we want to use .Net Core do we have to create the XAML files manually? Am I missing something? XAML is explicitly not listed under the .Net Core option, but the project creation process does indeed create XAML files in the project as expected.
With suggestions above, I was able to get this working in VS2019. To condense the answer:
In the project properties, ensure the "Output Type" is "Windows Application".
Ensure the target framework is ".Net 5.0"
Then directly edit the .csproj file by adding <UseWPF>true</UseWPF> to the first <PropertyGroup>.
Right-click on the project, select: Add > Window
I seem to have answered my own question but it seems useful so I will leave it up here. When you create your .Net Core WPF Application, if you choose .NetCore 3.1 (Long-term support) you get the behavior I describe above (no ability to add XAML windows). If you choose .NET 5.0 (Current) it works as expected and you can add XAML windows.

Missing Toolbox Items in VS 2013

I'm developing a WinForms application using Visual studio 2013. I have two user controls and 1 custom control in my project. Unfortunately for some reason they are not appearing in my toolbox at design. At one point they did briefly but disappeared and never returned. I have tried resetting the toolbox, checking the AutoPopulate option and made sure that my project is built. I've seen solutions about adding controls that exist in their own library but these exist within the same project. My classes also have a namespace and the ToolboxItem(True) attribute.
Thanks

Using AdControl to display ads in a WPF application packaged for UWP

I (appear to) have successfully created a UWP package for my WPF application using the following guide:
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net
Now I would like to take advantage of the AdControl class to display banner ads in my project, as detailed here:
https://learn.microsoft.com/en-us/windows/uwp/monetize/adcontrol-in-xaml-and--net
Is this possible? I don't see the "Universal Windows" section under References for my WPF project, which I can guess is because it’s not an original Universal Windows project. I do see it under References for the UWP package wrapper project I created using the guide above, but that doesn't help me show ads in the WPF project.
Any help appreciated.
You can add Universal Windows reference and use the API in your project as described here but you cannot use AdControl since XAML/UI in WPF is not the same as XAML in UWP and the AdControl is a UWP XAML control:
As mentioned above, there are exceptions to the rule that Windows 10
APIs are accessible from PC software. The first big exception concerns
XAML UI APIs. The XAML framework in UWP is different from the one in
WPF and you really don’t want to be mixing them up, anyways.

How can I make Visual Studio 2010's "Add User Control" create a WPF control?

I have a class library that I created using the "Class Library" project template. If I right-click on this library in Solution Explorer and select "Add > User Control", Visual Studio adds a WinForms UserControl. That's not what I want -- I want "Add > User Control" to add a WPF user control.
I've already added references to the WPF assemblies (WindowsBase, PresentationFramework, and PresentationCore), and I already have some WPF UserControls in this library, and everything compiles. My library does not have references to the WinForms assemblies (System.Drawing and System.Windows.Forms). But apparently the proper references are not enough of a clue for Visual Studio, because when I try Add > User Control, it adds the WinForms references to my project, and then creates a WinForms UserControl.
I can add a WPF User Control to my WPF Application project, and then move it into my library. But that's a pain, and I'd rather have it work properly in the first place.
I think I'm probably missing some kind of arcane XML element in my .csproj file that tells Visual Studio which designer to use by default, and if I add the right XML element with the right cryptic GUID, it will start working properly. If I could create a new WPF Control Library, I could probably compare the two project files and figure this out. However, I'm using Visual C# Express, which doesn't have a template for a WPF Control Library project, so I'm out of luck there.
What do I need to do to my Class Library's .csproj file so that VS2010's Add > New User Control will add a WPF UserControl?
There are sub-projects class ids in the project file that affect the Visual Studio context menus and how the project behaves in general. The easiest thing to do is to recreate the project as a:
WPF User Control Library
instead of a "Class Library". It is possible if you already created the project to edit in the sub-project class ids by hand by opening the ".csproj" file in a text editor such as Visual Studio itself but its easy to cause more damage than you fix that way.
I believe but haven't test that another type of library will also work:
WPF Custom Control Library
which is intended to hold other types of controls than UserControl objects but being a WPF sub-project type the context menus also work correctly for the use case you are describing.
Edit:
For completeness, I've just tested how to manually add the sub-project GUIDS. Add this line to the first PropertyGroup in the .csproj file:
<PropertyGroup>
...
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
Not tested with Visual Studio Express.

putting some WPF windows in DLL

I have a WPF project, and there is one dialog that I will re-use in different applications. I want to put it in its own DLL, but when I use the New Project wizard in Visual Studio 2008 it only lets me create WinForm C# DLLs. Am I missing something?
You should be able to create a WPF Custom Control Library project.
To add to this, this particular project does not actually show up unless you specifically choose Classic Desktop projects.

Resources