Exam 70-511 : Windows Applications Development with Microsoft .NET Framework 4 Part – 1

Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You write the following code fragment.
<StackPanel TextBox.PreviewTextInput="StackPanel_PreviewTextInput">
<TextBox Name="TxtBoxA"/>
<TextBox Name="TxtBoxB"/>
<TextBox Name="TxtBoxC"/>
</StackPanel>

You create an event handler named StackPanel_PreviewTextInput. You also have a collection of strings named Keywords. You need to ensure that TxtBoxA and TxtBoxB do not contain any of the strings in the Keywords collections. Which code segment should you use?

  1. private void StackPanel_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
    FrameworkElement feSource = sender as FrameworkElement;
    if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
    {
    foreach(string keyword in Keywords)
    {
    if(e.Text.Contains(keyword))
    {
    e.Handled = false;
    return;
    }
    }
    }
    e.Handled = true;
    }
    }
  2. private void StackPanel_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
    FrameworkElement feSource = e.Source as FrameworkElement;
    if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
    if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
    {
    foreach(string keyword in Keywords)
    {
    if(e.Text.Contains(keyword))
    {
    e.Handled = false;
    return;
    }
    }
    e.Handled = true;
    }
    }
  3. private void StackPanel_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
    FrameworkElement feSource = sender as FrameworkElement;
    if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
    {
    foreach(string keyword in Keywords)
    {
    if(e.Text.Contains(keyword))
    {
    e.Handled = true;
    return;
    }
    }
    e.Handled = false;
    }
    }
  4. private void StackPanel_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
    FrameworkElement feSource = e.Source as FrameworkElement;
    if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
    {
    foreach(string keyword in Keywords)
    {
    if(e.Text.Contains(keyword))
    {
    e.Handled = true;
    return;
    }
    }
    e.Handled = false;
    }
    }

Correct Answer: 4


Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. The application contains a composite user control that includes a TextBox control named txtInput. The user control will be hosted in a window and will have handlers for the text-changed event of txtInput. You need to ensure that the application meets the following requirements:

  • Creates a text-changed event handler named Audit_TextChanged for the txtInput control.
  • Executes Audit_TextChanged even when specific handlers mark the event as handled.

Which code segment should you add to the constructor of the user control

  1. txtInput.TextChanged += Audit_TextChanged;
  2. AddHandler(TextBox.TextChangedEvent, new RoutedEventHandler(Audit_TextChanged), true);
  3. EventManager.RegisterClassHandler(typeof(TextBox),TextBox.TextChangedEvent,new RoutedEventHandler(Audit_TextChanged), true);
  4. EventManager.RegisterClassHandler(typeof(TextBox),TextBox.TextChangedEvent,new RoutedEventHandler (Audit_TextChanged), false);

Correct Answer: 2


Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You create a window that contains a Button control and a MenuItem control. Both controls are labeled “Add sugar.” The Command properties of the Button and MenuItem controls are set to the same RoutedCommand named AddSugarCommand. You write the following code segment.
private void CanAddSugar (object sender, CanExecuteRoutedEventArgs e) { ... }
You need to ensure that when the CanAddSugar method sets e.CanExecute to false, the MenuItem and Button controls are disabled. What should you do

  1. Create an event handler for the CanExecuteChanged event of the AddSugarCommand command. Call the CanAddSugar method from within the event handler.
  2. Inherit the AddSugarCommand from the RoutedUICommand class instead of the RoutedCommand class. Call the CanAddSugar method from within the constructor of the AddSugarCommand command.
  3. Add a CommandBinding object to the CommandBinding property of the MenuItem control. Set the CanExecute property of the CommandBinding object to the CanAddSugar method.
  4. Add a CommandBinding object to the CommandBindings property of the window. Set the Command property of CommandBinding to the AddSugarCommand command. Set the CanExecute property of the CommandBinding object to the CanAddSugar method.

Correct Answer: 4


Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. The application has a window named MainWindow that has a StackPanel control named sp as the root element. You want to create a Button control that contains a TextBlock control with the “Save” Text property. You need to create the control dynamically and add the control to sp. Which code segment should you write in the constructor of the MainWindow class

  1. Button btn = new Button();
    TextBlock text = new TextBlock();
    text.Text = "Save";
    btn.Content = text;
    sp.DataContext = btn;
  2. Button btn = new Button();
    TextBlock text = new TextBlock();
    text.Text = "Save";
    btn.Content = text;
    sp.Children.Add(btn);
  3. Button btn = new Button();
    TextBlock text = new TextBlock();
    text.Text = "Save";
    sp.Children.Add(btn);
    sp.Children.Add(text);
  4. Button btn = new Button();
    TextBlock text = new TextBlock();
    text.Text = "Save";
    btn.ContentTemplateSelector.SelectTemplate(text, null);
    sp.Children.Add(btn);

Correct Answer: 4


Question: You create a Windows client application by using Windows Presentation Foundation (WPF). The application contains the following code fragment.
<Window.Resources>
<DataTemplate x:Key="detail">
<!--...-->
</DataTemplate>
</Window.Resources>
<StackPanel>
<ListBox Name="lbDetails">
</ListBox>
<Button Name="btnDetails">Details</Button>
</StackPanel>

You need to assign lbDetails to use the detail data template when btnDetails is clicked. Which code segment should you write for the click event handler for btnDetails

  1. lbDetails.ItemsPanel.FindName(“detail”,lbDetails);
  2. var tmpl = (ControlTemplate)FindResource(“detail”); lbDetails.Template = tmpl;
  3. var tmpl = (DataTemplate)FindName(“detail”); lbDetails.ItemTemplate = tmpl;
  4. var tmpl = (DataTemplate)FindResource(“detail”); lbDetails.ItemTemplate=tmpl;

Correct Answer: 4

Tagged . Bookmark the permalink.

Leave a Reply