我有 MyUserControl 类,它扩展了 UserControl,带有一个参数:
namespace MyNameSpace
{
public partial class MyUserControl: UserControl
{
public MyUserControl()
{
InitializeComponent();
}
private Control _owner;
public Control Owner
{
set { _owner = value; }
get { return _owner; }
}
}
}
例如,如何将 XAML 中的 Grid 作为该参数传递?
<Window x:Class="MyNameSpace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:my="clr-namespace:MyNameSpace">
<Grid x:Name="grid1">
<my:MyUserControl x:Name="myUserControl1" Parent="*grid1?*" />
</Grid>
</Window>