我正在准备考试和学习问题。然而,我有一个问题,在我看来,答案是错误的。这里就是正确答案是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