【发布时间】:2011-01-05 21:30:03
【问题描述】:
注意:应要求,我已为我的 XAML 和 xaml.cs 文件添加了完整代码。
在 WPF 中,我创建了一个 DockPanel,如下所示:
<Window x:Class="RealEditor.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="RealEditor" Height="500" Width="700">
<DockPanel>
<GridSplitter Grid.Column="1" Width="4" HorizontalAlignment="Left"/>
<DockPanel x:Name="ftpDock" Grid.Row="1" Grid.Column="1"></DockPanel>
</Grid>???
</DockPanel>
</Window>
我想以编程方式将 TreeView 添加到 DockPanel,但在 Window1.xaml.cs 中,我无法按名称获取 DockPanel 并将其添加:
namespace RealEditor
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
TreeViewItem mytreeView = new TreeViewItem();
ftpDock.Children.Add(myTreeView);
}
}
}
以上代码返回如下错误:
"The name 'ftpDock' does not exist in the current context"
我确定我错过了一些简单的事情。有什么想法吗?
【问题讨论】:
-
显示更多代码、XAML 和后面的代码。
标签: c# wpf wpf-controls dockpanel