我正在準備考試和學習問題。然而,我有一個問題,在我看來,答案是錯誤的。這裏就是正確答案是d問題:證書和問題的正確答案
您使用的Microsoft .NET Framework 4 創建的Windows Presentation 基金會(WPF)應用程序。 應用程序有一個名爲 的窗口,該窗口具有名爲sp的StackPanel 控件作爲根元素。 您想要創建一個Button控件 ,其中包含一個TextBlock控件,其中包含 「保存」文本屬性。您需要動態創建控件並將 控件添加到sp。
Button btn = new Button(); TextBlock text = new TextBlock(); text.Text = "Save"; btn.Content = text; sp.DataContext = btn;
B::你應該在 構造MainWindow類
一個寫哪段代碼
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.Content = text;
sp.Children.Add(btn);
C:
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
sp.Children.Add(btn);
sp.Children.Add(text);
d:
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.ContentTemplateSelector.SelectTemplate(text, null);
sp.Children.Add(btn);
在我看來,正確答案是B?你有任何sugesstions?
我認爲你是正確的,B是正確答案崩潰。其他答案不正確。 – Sonorx 2011-03-20 13:49:54
從不編碼的.NET或WPF,但我也選擇B.它似乎正確地分配兩個對象的屬性。 – Blender 2011-03-20 13:54:08