Ok, so I've been looking all over for a anwser, but I starting to wonder if I would even know it if I saw it. I'm new to WPF, but have been doing Windows Forms in C# for a few years now.
My Question is: Why can't I access a label from the code behind that I "dragged-n-dropped" on to the grid and renamed?
XML CODE:
<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>
The particular label I'm refereing to is the last label in the first GroupBox named "LBL_StartTimeConvert"
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="221,89,0,0" Name="LBL_StartTimeConvert" VerticalAlignment="Top" Width="128" />
When I go into the Code behind file, I am unable to get "LBL_StartTimeConvert" to show up in intellisense. How do I access this label from the C# code? I need to change the labels text. Thanks!
PS>> Any good resources/books that you can point me to on learning WPF (like WPF 101 or WPF for Dummies) would be much appreciated!
I had the same problem. A restart of VS solved it. Sometimes it really is a bug ;)
Please make sure your namespace and window name is same in code behind as xaml file cause when I have pasted your code in my sample window, it working fine and also I can access label LBL_StartTimeConvert.
Please create new sample WPF project and put your code which is inside <grid>
tag and then check it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With