将子项添加到用户控件 [英] Add child to user control
本文介绍了将子项添加到用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在设计视图中将控件添加到WpF中的用户控件?
解决方案
我想我理解你的意思:如何创建一个UserControl,其中包含一个内容:
[ContentProperty( PlaceHolder)]
public partial class UserControl1:UserControl
{
public UserControl1()
{
InitializeComponent();
}
public object PlaceHolder
{
get
{
return 此跨度> .contentPresenter.Content;
}
设置
{
此 .contentPresenter .Content = value ;
}
}
}
< UserControl x:Class = WpfApplication9.UserControl1
xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
< span class =code-attribute> xmlns:x = http://schemas.microsoft.com/ winfx / 2006 / xaml
< span class =code-attribute> xmlns :mc = http://schemas.openxmlformats.org/markup-compatibility/2006
xmlns:d = http: //schemas.microsoft.com/expression/blend/2008\" DockPanel LastChildFill = True >
mc:可忽略 = d
d:DesignHeight = 300 d:DesignWidth = 300 >
<
< Border 已删除 = Plum DockPanel.Dock = Top 高度 = 50 / >
< Border 已移除 = 蓝色 DockPanel.Dock = 底部 高度 = 50 / >
< ContentPresenter x:名称 = contentPresenter / >
< / DockPanel >
< / UserControl >
How to add controls to a user control in WpF in the design view?
解决方案
Hi,
I think that I understand what you mean: How to create a UserControl with a place for his content:
[ContentProperty("PlaceHolder")] public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public object PlaceHolder { get { return this.contentPresenter.Content; } set { this.contentPresenter.Content = value; } } }
<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>
这篇关于将子项添加到用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文