What should you do to ensure that the XAML code fragment sorts the list of available cars correctly?

You are creating a Windows Presentation Foundation application for a car dealer. You use Microsoft .NET Framework 3.5 to create the application.
You are creating a window that will display a list of available cars. The list will be sorted on the basis of the Make property. You try to run the XAML code fragment for the window. The following section of the code fragment does not compile.
(Line numbers are included for reference only.)

01 <Window.Resources>
02 …
03 <CollectionViewSource x:Key="vw" Source="{StaticResource cars}">
05 <CollectionViewSource.SortDescriptions>
06 <SortDescription PropertyName="Make" />
07 </CollectionViewSource.SortDescriptions>
08 </CollectionViewSource>
09 </Window.Resources>
You receive the following error message: "Type ‘SortDescriptions’ was not found."
You need to ensure that the XAML code fragment sorts the list of available cars correctly.
What should you do?

You are creating a Windows Presentation Foundation application for a car dealer. You use Microsoft .NET Framework 3.5 to create the application.
You are creating a window that will display a list of available cars. The list will be sorted on the basis of the Make property. You try to run the XAML code fragment for the window. The following section of the code fragment does not compile.
(Line numbers are included for reference only.)

01 <Window.Resources>
02 …
03 <CollectionViewSource x:Key=”vw” Source=”{StaticResource cars}”>
05 <CollectionViewSource.SortDescriptions>
06 <SortDescription PropertyName=”Make” />
07 </CollectionViewSource.SortDescriptions>
08 </CollectionViewSource>
09 </Window.Resources>
You receive the following error message: “Type ‘SortDescriptions’ was not found.”
You need to ensure that the XAML code fragment sorts the list of available cars correctly.
What should you do?

A.
Replace line 06 of the XAML code fragment with the following code fragment.
<componentModel:SortDescription PropertyName=”Make” xmlns:componentModel=”clr-namespace:System.ComponentModel;assembly=System”/>

B.
Replace line 06 of the XAML code fragment with the following code fragment.
<componentModel:SortDescription PropertyName=”Make” xmlns:componentModel=”clr-namespace:System.ComponentModel;assembly=WindowsBase”/>

C.
Add the following code segment immediately after the IntializeComponent method call in the constructor.
BindingListCollectionView view = (BindingListCollectionView)(CollectionViewSource.GetDefaultView(lst.ItemsSource));
if (view != null)
view.SortDescriptions.Add(new SortDescription(“Make”, ListSortDirection.Ascending));

D.
Remove lines 03 through 08 from the XAML code fragment. Add the following code segment immediately after the InitializeComponent method call in the constructor.
BindingListCollectionView view = (BindingListCollectionView)(CollectionViewSource.GetDefaultView(lst.ItemsSource));
if (view != null)
view.SortDescriptions.Add(new SortDescription(“Make”, ListSortDirection.Ascending));



Leave a Reply 0

Your email address will not be published. Required fields are marked *