Ale*_*dra 4 silverlight user-controls code-behind silverlight-3.0
在Silverlight 3的前几个小时里,作为狂热的WPF用户,我对它不支持的许多事情感到非常失望.这对我来说似乎是一个奇怪的问题,它是如此通用,我无法在网上找到任何关于它的东西.
我有以下XAML:
<controls:TabControl x:Name="workspacesTabControl" Grid.Row="1"
Background="AntiqueWhite" ItemsSource="{Binding Workspaces, ElementName=_root}"/>
Run Code Online (Sandbox Code Playgroud)
但是,我无法看到workspacesTabControl代码隐藏.我想也许IntelliSense只是意味着并试图继续编译它,但是有一个错误:
Error 1 The name 'workspacesTabControl' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
如何在代码隐藏中访问控件?
编辑:我意识到我粘贴了错误的错误 - 我在UserControl中有两个名为workspacesTabControl和menuStrip的控件.在代码隐藏中,我无法通过他们的名字找到其中任何一个.
以防万一,这里是XAML menuStrip:
<controls:TreeView Grid.ColumnSpan="2" Height="100" x:Name="menuStrip"
ItemContainerStyle="{StaticResource MenuStripStyle}"
ItemsSource="{Binding Menu, ElementName=_root}"/>
Run Code Online (Sandbox Code Playgroud)
再次编辑:
我不确定这是否有用,但我已经看了一下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));
}
Run Code Online (Sandbox Code Playgroud)
它似乎只是在运行时(不是在编译之前或编译期间)加载XAML,因此menuStrip和workspacesTabControl名称实际上并没有在任何地方注册(因为它们通常在WPF/win表单中).该属性可能是个问题吗?我在哪里可以摆脱所有未来UserControls的这个要求?
小智 22
检查VS中的属性以获取xaml文件本身...确保将Build Action设置为Page.