Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

How to add controls to a user control in WpF in the design view?

Posted
Comments
Michael Haephrati 9-Mar-13 6:56am    
Please clarify your question

1 solution

Hi,

I think that I understand what you mean: How to create a UserControl with a place for his content:

C#
[ContentProperty("PlaceHolder")]
public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }

    public object PlaceHolder
    {
        get
        {
            return this.contentPresenter.Content;
        }
        set
        {
            this.contentPresenter.Content = value;
        }
    }
}


XML
<UserControl x:Class="WpfApplication9.UserControl1"
             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">
    <DockPanel LastChildFill="True">
        <Border removed="Plum" DockPanel.Dock="Top" Height="50" />
        <Border removed="Blue" DockPanel.Dock="Bottom" Height="50" />
        <ContentPresenter x:Name="contentPresenter" />
    </DockPanel>
</UserControl>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900