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 data-bound 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.)
- Implement the validation rules inside the Validating event handler of each TextBox control by throwing an exception when the value is invalid.
- Implement the validation rules inside the TextChanged event handler of each TextBox control by throwing an exception when the value is invalid.
- Implement the validation rules inside the setter of each property of the Customer class by throwing an exception when the value is invalid.
- Add the following code segment to the InitializeComponent method of the Windows Form.
this.errorProvider.DataSource = this.customerBindingSource;
- 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 Visual Studio 2010 and Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. The application contains a ListBox control named IbxItems that is data-bound to a collection of objects. Each object has a DisplayValue property. You add a Button control to the application. You need to ensure that the Content property of the Button control is data-bound to the DisplayValue property of the selected item of IbxItems. Which binding expression should you use?
- {Binding ElementName= IbxItems, Source=SelectedItem, Path=DisplayValue}
- {Binding Source=lbxItems, ElementName=SelectedItem, Path=DisplayValue}
- {Binding ElementName=lbxItems, Path=SelectedItem.DisplayValue}
- {Binding Source=lbxItems, Path=SelectedItem.DisplayValue}
Correct Answer: 3
Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You write the following code fragment.
< TextBox Text="{BindingPath=StringMember} " / >
You need to ensure that the StringMember property of the data-bound object is updated immediately when the user types in the TextBox control. Which binding expression should you use?
- { Binding Path=StringMember, Mode=TwoWay }
- { Binding Path=StringMember, NotifyOnSourceUpdated=True }
- { Binding Path-StringMember, NotifyOnTargetUpdated=True }
- { Binding Path=StringMember, UpdateSourceTrigger=PropertyChanged }
Correct Answer: 4
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You add a ListBox control to the application. The ListBox control is data-bound to an instance of a custom collection class of the Product objects named ProductList. The number of items of the data-bound collection is fixed. However, users can modify the properties of each of the Product objects in the collection. You need to ensure that changes made on the Product objects are automatically reflected in the ListBox control. What should you do?
- Implement the INotifyPropertyChanged interface in the Product class.
- Implement the INotifyCollectionChanged interface in the ProductList class.
- Set the Mode property of the Binding object of the ListBox control to TwoWay.
- Set the UpdateSourceTrigger property of the Binding object of the ListBox control to PropertyChanged.
Correct Answer: 1
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You write the following code fragment. You need to implement the MyProject.MyConverter class. What should you do?
- Implement the IValueConverter interface.
- Implement the IMultiValueConverter interface.
- Inherit from the TypeConverter class.
- Apply the TypeConverterAttribute attribute.
Correct Answer: 1
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. The application contains an ObservableCollection object named Pictures that contains several Picture objects. Each Picture object contains the Name and PictureFilePath properties. You add a ListBox control to the application. You need to ensure that the pictures are displayed in the ListBox control. Which code fragment should you use?
<ListBox ItemsSource="{Binding Source={StaticResource pictures})"> <ListBox. ItemTeroplato <DataTemplate> <TextBlockXTextBlock.Text> <Binding Path="PictureFilePath" /> </TextBlock.TextX/TextBlock> </DataTemplate> </ListBox.ItemTemplate> </LiscBox>
<ListBox ItemsSource-"{Binding Source-{StaticResoucce pictures})"> <ListBox. ItemTeroplato <DataTemplate> <Image Source="{Binding Source={StaticResource pictures}/ Path=PictureFilePath}"/> </DataTeroplate> </ListBox.ItemTemplate> </ListBox>
<ListBox ItemsSource-"(Binding Source-{StaticResource pictures)} "> <ListBox. IteroTemplate> <DataTemplate> <TextBlockXTextBlock.Text> <Binding Path="Name" /> </TextBlock.Text></TextBlock> </DataTemplate> </ListBox. ItemTeroplato </LiscBox>
<ListBox ItemsSource="(Binding Source{StaticResource pictures)>"> <ListBox. ItemTemplato <DataTemplate> <Iroage Source="{Binding Path=PictureFiiePath)"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
Correct Answer: 4
Question: You use Microsoft .NET Framework 4 to create a Windows Forms application. You have a dataset as shown in the following exhibit. You plan to add a DataGridView to display the dataset. You need to ensure that the DataGridView meets the following requirements:
- Shows Order Details for the selected order.
- Shows only Order Details for items that have UnitPrice greater than 20
- Sorts Products by ProductName
Which code segment should you use?
ordersBindingSource.DataSource = producxsBindingSource; ordersBindingSource.DataMember = "FK_Order_Details_Products"; productsBindingSource.Filter = "UnitPrice > 20"; productsBindingSource.Sort = ProductName";
productsDataGridView.DataSource = ordersBindingSource; productsBindingSource.Filter = "UnitPrice > 20"; productsBindingSource.Sort = "ProductName";
order DetailsBindingSource.DataSource = ordersBindingSource; order_DetailsBindingSource.DataMember = "FK_Order_Details_Orders". order_DetailsBindingSource .Filter = "UnitPrice > 20"; productsBindingSource.Sort "ProductName";
order_DetailsDataGridViev.DataSource = ordersBindingSource; order_DetailsBindingSource.Filter = "UnitPrice > 20"; productsBindingSource.Sort "ProductName";
Correct Answer: 3