Reputation: 12252
I created a custom wpf control and added it to my xaml. This works. However, if I put the custom control in another project and try to include it from there, it is not visible when I run my application. The right control ("CustomViewDirectly") in the attached example is from the same project and the left control ("CustomView") from the referenced project. How can I correctly include the CustomView / make it visible? I use VisualStudio2012 Update 4.
Example Solution: http://pvcell.wikispaces.com/file/view/WpfTest.zip/513722714/WpfTest.zip
Some code snippets:
<Window x:Class="Main.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="clr-namespace:WpfTest.Core"
xmlns:core1="clr-namespace:Utils.Core;assembly=Utils"
Title="MainWindow" Height="350" Width="525">
<Grid>
<core:CustomViewDirectly HorizontalAlignment="Right"/>
<core1:CustomView HorizontalAlignment="Left" Width="100" Height="100"/>
</Grid>
</Window>
-
<UserControl x:Class="Core.CustomViewDirectly"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Background="Black" >
<Button Content="Directly" HorizontalAlignment="Left" Height="51" Margin="87,110,0,0" VerticalAlignment="Top" Width="121"/>
</Grid>
</UserControl>
-
<UserControl x:Class="Core.CustomView"
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"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="100">
<Grid Background="#FFEE0D0D">
<Button Content="Referenced" HorizontalAlignment="Left" Height="51" Margin="0,27,0,0" VerticalAlignment="Top" Width="100"/>
</Grid>
</UserControl>
Upvotes: 0
Views: 177
Reputation: 8150
You should use a "WPF User Control Library" project, instead of a "Class Library" project for your custom controls.
Upvotes: 1