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

Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You want to add an audio player that plays .wav or .mp3 files when the user clicks a button. You plan to store the name of the file to a variable named SoundFilePath. You need to ensure that when a user clicks the button, the file provided by SoundFilePath plays. What should you do

  1. Write the following code segment in the button onclick event.
    System.Media.SoundPlayer player = new System.Media.SoundPlayer(SoundFilePath); player.play();
  2. Write the following code segment in the button onclick event.
    MediaPlayer player = new MediaPlayer();
    player.Open(new URI(SoundFilePath), UriKind.Relative));
    player.play();
  3. Use the following code segment from the PlaySound() Win32 API function and call the PlaySound function in the button onclick event.
    [sysimport(dll="winmm.dll")]
    public static extern long PlaySound(String SoundFilePath, long hModule, long dwFlags);
  4. Reference the Microsoft.DirectX Dynamic Link Libraries. Use the following code segment in the button onclick event.
    Audio song = new Song(SoundFilePath);
    song.CurrentPosition = song.Duration;
    song.Play();

Correct Answer: 2


Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You write the following code fragment.
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<EventSetter Event="Click" Handler="ButtonHandler"/>
</Style>
</StackPanel.Resources>
<Button Name="OkButton">Ok</Button>
<Button Name="CancelButton" Click="CancelClicked">Cancel</Button>
</StackPanel>

You need to ensure that the ButtonHandler method is not executed when the user clicks the CancelButton button. Which code segment should you add to the code-behind file

  1. private void CancelClicked(object sender, RoutedEventArgs e)
    {
    Button btn = (Button)sender;
    btn.Command = null;
    }
  2. private void CancelClicked(object sender, RoutedEventArgs e)
    {
    Button btn = (Button)sender;
    btn.IsCancel = true;
    }
  3. private void CancelClicked(object sender, RoutedEventArgs e)
    {
    e.Handled = true;
    }
  4. private void CancelClicked(object sender, RoutedEventArgs e)
    {
    e.Handled = false;
    }

Correct Answer: 3


Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You create a WPF window in the application. You add the following code segment to the application.
public class ViewModel
{
public CollectionView Data { get; set; }
}
public class BusinessObject
{
public string Name { get; set; }
}

The DataContext property of the window is set to an instance of the ViewModel class. The Data property of the ViewModel instance is initialized with a collection of BusinessObject objects.You add a TextBox control to the Window. You need to bind the Text property of the TextBox control to the Name property of the current item of the CollectionView of the DataContext object. You also need to ensure that when a binding error occurs, the Text property of the TextBox control is set to N/A . Which binding expression should you use

  1. { Binding Path=Data/Name, FallbackValue=’N/A’ }
  2. { Binding Path=Data.Name, FallbackValue=’N/A’ }
  3. { Binding Path=Data/Name, TargetNullValue=’N/A’ }
  4. { Binding Path=Data.Name, TargetNullValue=’N/A’ }

Correct Answer: 1


Question: You use Microsoft .NET Framework 4 to create a Windows Forms application. You add a new class named Customer to the application. You select the Customer class to create a new object data source. You add the following components to a Windows Form:

  • A BindingSource component named customerBindingSource that is data-bound to the Customer object data source.
  • A set of TextBox controls to display and edit the Customer object properties. Each TextBox control is databound to a property of the customerBindingSource component.
  • An ErrorProvider component named errorProvider that validates the input values for each TextBox control.

You need to ensure that the input data for each TextBox control is automatically validated by using the ErrorProvider component. Which two actions should you perform (Each correct answer presents part of the solution. Choose two.)

  1. Implement the validation rules inside the Validating event handler of each TextBox control by throwing an exception when the value is invalid.
  2. Implement the validation rules inside the TextChanged event handler of each TextBox control by throwing an exception when the value is invalid.
  3. Implement the validation rules inside the setter of each property of the Customer class by throwing an exception when the value is invalid
  4. Add the following code segment to the InitializeComponent method of the Windows Form.
    this.errorProvider.DataSource = this.customerBindingSource;
  5. Add the following code segment to the InitializeComponent method of the Windows Form.
    this.errorProvider.DataSource = this.customerBindingSource.DataSource;
    this.errorProvider.DataMember = this.customerBindingSource.DataMember;

Correct Answer: 3 & 4


Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You write the following code segment. (Line numbers are included for reference only.)
01public class Contact
02{
03private string _contactName;
04
05public string ContactName {
06get { return _contactName; }
07set { _contactName = value; }
08}
09
10}
You add the following code fragment within a WPF window control.
<TextBox>
<TextBox.Text>
<Binding Path="ContactName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>

The TextBox control is data-bound to an instance of the Contact class. You need to ensure that the Contact class contains a business rule to ensure that the ContactName property is not empty or NULL. You also need to ensure that the TextBox control validates the input data. Which two actions should you perform (Each correct answer presents part of the solution. Choose two).

  1. Replace line 01 with the following code segment.
    public class Contact : IDataErrorInfo
  2. Replace line 01 with the following code segment.
    public class Contact : ValidationRule
  3. Replace line 01 with the following code segment.
    public class Contact : INotifyPropertyChanging
  4. Add the following code segment at line 04.
    public event PropertyChangingEventHandler PropertyChanging;
  5. Modify line 07 with the following code segment :
    set
    {
    if (this.PropertyChanging != null)
    PropertyChanging(this, new PropertyChangingEventArgs("ContactName"));
    if (string.IsNullOrEmpty(value))
    throw new ApplicationException("Contact name is required");
    _contactName = value;
    }

    F. Add the following code segment at line 09.
    public string Error {
    public string this[string columnName]
    {
    get
    {
    if (columnName == "ContactName" && string.IsNullOrEmpty(this.ContactName))
    return "Contact name is required";
    return null;
    }
    }

Correct Answer: 1 & 5

Tagged . Bookmark the permalink.

Leave a Reply