我有以下XAML:
<controls:TabControl x:name="workspacesTabControl" GrID.Row="1"Background="AntiqueWhite" ItemsSource="{Binding Workspaces,Elementname=_root}"/>
但是,我无法在代码隐藏中看到workspacesTabControl.我想也许IntelliSense只是意味着并试图继续编译它,但是有一个错误:
Error 1 The name 'workspacesTabControl' does not exist in the current context
如何在代码隐藏中访问控件?
编辑:我意识到我粘贴了错误的错误 – 我在UserControl中有两个名为workspacesTabControl和menuStrip的控件.在代码隐藏中,我无法通过他们的名字找到其中任何一个.
以防万一,这里是menuStrip的XAML:
<controls:TreeVIEw GrID.ColumnSpan="2" Height="100" x:name="menuStrip" ItemContainerStyle="{StaticResource MenuStripStyle}" ItemsSource="{Binding Menu,Elementname=_root}"/>
再次编辑:
我不确定这是否有用,但我已经看了一下InitializeComponent()代码,这就是我所看到的:
[System.Diagnostics.DeBUGgerNonUserCodeAttribute()]public voID InitializeComponent() { if (_contentLoaded) { return; } _contentLoaded = true; System.windows.Application.LoadComponent(this,new System.Uri("/SapphireApplication;component/SapphireMain.xaml",System.UriKind.relative));}
它似乎只是在运行时(不是在编译之前或编译期间)加载XAML,因此menuStrip和workspacesTabControl名称实际上并未在任何地方注册(因为它们通常在WPF / win表单中).该属性可能是个问题吗?我在哪里可以摆脱所有未来UserControls的这个要求?
解决方法 检查VS中的属性以获取xaml文件本身…确保将Build Action设置为Page. 总结以上是内存溢出为你收集整理的在代码中看不到命名的Silverlight控件全部内容,希望文章能够帮你解决在代码中看不到命名的Silverlight控件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)