Reputation: 8551
I have a very simple two-project solution in Visual Studio 2015 Community. One project is a WPF application; the other is a class library. I have added a project reference in the main project to the class library. The class library contains one WPF UserControl named TestControl
with the following XAML:
<UserControl x:Class="SomeControls.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SomeControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="38,29,0,0" VerticalAlignment="Top" Width="75"/>
<CheckBox x:Name="checkBox" Content="CheckBox" HorizontalAlignment="Left" Margin="163,40,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="83,102,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="121" Width="164"/>
</Grid>
</UserControl>
The only controls it contains are standard WPF controls.
The class library project builds successfully, and when I open the WPF designer for the main window in the WPF Application project, the TestControl
control from the class library appears in the Toolbox. But when I select that control from the Toolbox and try to add an instance to my main window, I get a dialog that states:
The following reference has been added to the project:
"SomeControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
In order to use types from the new reference, press OK to restart the XAML Designer. After the XAML Designer restarts, re-create the control on the artboard.
When I click "OK," nothing changes, and if I try to add the control again, I get the same error dialog. I have tried closing and re-opening the XAML file as well as closing and re-opening Visual Studio.
Why won't Visual Studio let me add a control from a referenced project via the designer?
Here is a screenshot showing my setup and the dialog I get:
Upvotes: 2
Views: 1524
Reputation: 1
1.Select "SomeControls" in "Reference, and set "Copy Local" to true.
2.Then build your "wpfApplication1"
Upvotes: 0
Reputation: 39
Clear everything related with your DLL in reference and toolbox. Close the VS and then :
Upvotes: 0
Reputation: 2945
Clear everything related with custom control currently. Drag the DLL directly to the Toolbox, no need to add the reference seperately. This dragging operation makes everything you need. It adds the DLL as reference, the xmlns namespace and the assembly name automatically.
I tested it using your code and it works.
Upvotes: 2