Hi,
>>如果没有,那么我如何动态创建wpf对象呢?
WPF没有专门的方法来插入对象。 你可以在后台动态的创建元素,并可以放到任意地方, 你只是要给某个容器控件添加有个名称。例如:
public partial class Window29 : Window
{
public Window29()
{
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Button btn = new Button();
btn.Width = 60;
btn.Height = 30;
btn.Content = "Click Me";
myGrid.Children.Add(btn);
}
}
<Window x:Class="WpfTest.Window29"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfTest"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="Window29" Height="600" Width="600">
<Grid x:Name="myGrid">
</Grid>
</Window>
Best Regards,
Bob
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.