WPF:标签未显示在后面的代码中

标签 wpf wpf-controls code-behind

好的,所以我一直在寻找答案,但我开始怀疑如果我看到它是否会知道它。我是 WPF 的新手,但几年来一直在 C# 中使用 Windows 窗体。

我的问题是:为什么我不能从我“拖放”到网格上并重命名的代码中访问标签?

XML代码:

<Window x:Class="IMCommand.NewProblemWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="New Problem" Height="800" Width="800" Loaded="Window_Loaded">
    <Grid>
        <GroupBox Header="Initial Detection and Recording" Height="168" HorizontalAlignment="Left" Margin="12,45,0,0" Name="groupBox1" VerticalAlignment="Top" Width="754" FontSize="15">
            <Grid>
                <Label Content="Application/Server" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" />
                <TextBox Height="23" HorizontalAlignment="Left" Margin="144,11,0,0" Name="textBox1" VerticalAlignment="Top" Width="324" Background="#FFCBCBCB"></TextBox>

                <Label Content="AE Problem Ticket #" Height="28" HorizontalAlignment="Left" Margin="6,52,0,0" Name="label2" VerticalAlignment="Top" />
                <TextBox Background="#FFCBCBCB" Height="23" HorizontalAlignment="Left" Margin="155,54,0,0" Name="BOX_AEProblem" VerticalAlignment="Top" Width="175" />

                <Label Content="Start Time" Height="28" HorizontalAlignment="Left" Margin="6,86,0,0" Name="label4" VerticalAlignment="Top" Width="85" />
                <TextBox Height="23" HorizontalAlignment="Left" Margin="97,91,0,0" Name="BOX_StartTime" VerticalAlignment="Top" Width="118" IsReadOnly="True" />

                <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="221,89,0,0" Name="LBL_StartTimeConvert" VerticalAlignment="Top" Width="128" />
            </Grid>
        </GroupBox>

        <GroupBox Header="Classification and Initial Support" Height="333" HorizontalAlignment="Left" Margin="12,260,0,0" Name="groupBox2" VerticalAlignment="Top" Width="754" FontSize="15">
            <Grid>
                <Label Content="Description" Height="28" HorizontalAlignment="Left" Margin="6,96,0,0" Name="LBL_Description" VerticalAlignment="Top" />
                <RichTextBox Height="137" HorizontalAlignment="Left" Margin="97,96,0,0" Name="richTextBox1" VerticalAlignment="Top" Width="590" Background="#FFCBCBCB" Cursor="IBeam" ToolTip="Describe the problem..." VerticalScrollBarVisibility="Visible" SpellCheck.IsEnabled="True" FontSize="12" BorderBrush="#FF151414" />
                <RichTextBox Height="28" HorizontalAlignment="Left" Margin="97,44,0,0" Name="richTextBox2" VerticalAlignment="Top" Width="590" Background="#FFCBCBCB" />
                <Label Content="Summary" Height="28" HorizontalAlignment="Left" Margin="6,44,0,0" Name="label3" VerticalAlignment="Top" />
            </Grid>
        </GroupBox>
    </Grid>
</Window>

我所指的特定标签是第一个名为“LBL_StartTimeConvert”的 GroupBox 中的最后一个标签
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="221,89,0,0" Name="LBL_StartTimeConvert" VerticalAlignment="Top" Width="128" />

当我进入代码隐藏文件时,我无法让“LBL_StartTimeConvert”显示在智能感知中。如何从 C# 代码访问此标签?我需要更改标签文本。谢谢!

PS>> 任何您可以指点我学习 WPF(如 WPF 101 或 WPF for Dummies)的好资源/书籍将不胜感激!

最佳答案

我有同样的问题。重新启动VS解决了它。
有时它真的是一个错误;)

关于WPF:标签未显示在后面的代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7103111/

相关文章:

c# - 如何在新的 AppDomain 中运行 WPF 应用程序? ExecuteAssembly 失败

c# - 更改事件之前的 wpf 依赖属性?

c# - 为什么此代码会导致 "The name does not exist in the current context"错误?

wpf - 如何在 UserControl 和父窗口之间绑定(bind) WPF 命令

c# - 我可以在 WPF 中使用 NotifyIcon 吗?

wpf - 是否有任何 native WPF 多选组合框可用?

c# - 如何在代码中分配动态资源样式?

c# - 将 datetimepicker 的值传递给代码隐藏 (c#)

wpf - 在 WPF 中制作日志窗口的建议