8
有没有办法将用户控件添加到在代码中创建的WPF窗口?我无法在窗口类中找到Children属性。在XAML它应该是这样的:在代码中添加WPF UserControl到代码
<Window x:Class="MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyUserControls="clr-namespace:MyUserControls"
Title="" Height="Auto" Width="550" ResizeMode="NoResize">
<MyUserControls:UC1 x:Name="uc1" />
</Window>
在代码中,我想是这样的:
Window myWindow = new Window;
UC1 uc1 = new UC1;
myWindow.Children.Add(UC1);
感谢您的帮助
这只是我输入问题时写的伪代码。窗口类中没有Children属性。这是我的问题 – Basti 2011-05-20 06:49:48