好的,所以我一直在尋找一個anwser,但我開始懷疑,如果我看到它,我是否會知道它。我是WPF的新手,但現在已經在C#中使用Windows Forms了幾年了。WPF:標籤沒有顯示在代碼後面
我的問題是:爲什麼我不能從後面的代碼中訪問一個標籤,然後將它「拖放」到網格中並重命名?
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>
我refereing於特定的標籤是在名爲「LBL_StartTimeConvert」
<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)都會非常感謝!
當您在代碼後面的文件中使用LBL_StartTimeConvert時,您的項目是否會編譯?我想這只是IntelliSense的一個問題。 – Stephan
不,如果我嘗試手動輸入名稱,它會立即引發錯誤。 – Tom
沒有足夠的信息來回答你的問題。您嘗試訪問LBL_StartTimeConvert的方法是什麼?你可以添加代碼背後的代碼和你期望LBL_StartTimeConvert可訪問的例子嗎? – chuckj