Which XAML code fragment should you use?

You are creating a Windows Presentation Foundation application to track customer orders.
You use Microsoft .NET Framework 3.5 to create the application. The application contains an Order class. The Order class has two public properties named OrderDate and OrderID. The application also contains an ObservableCollection collection of Order objects. This collection is named OrderItems. You write the following XAML code fragment.
<Window.Resources>
<CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=OrderItems}" x:Key="orders" />
</Window.Resources>
You add two ListBox controls to select orders based on the OrderID or the OrderDate properties. One ListBox control displays order dates and the other ListBox control displays order numbers. You need to bind the two ListBox controls so that the item selected in one control is reflected in the other control.
Which XAML code fragment should you use?

You are creating a Windows Presentation Foundation application to track customer orders.
You use Microsoft .NET Framework 3.5 to create the application. The application contains an Order class. The Order class has two public properties named OrderDate and OrderID. The application also contains an ObservableCollection collection of Order objects. This collection is named OrderItems. You write the following XAML code fragment.
<Window.Resources>
<CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=OrderItems}" x:Key="orders" />
</Window.Resources>
You add two ListBox controls to select orders based on the OrderID or the OrderDate properties. One ListBox control displays order dates and the other ListBox control displays order numbers. You need to bind the two ListBox controls so that the item selected in one control is reflected in the other control.
Which XAML code fragment should you use?

A.
<ListBox Name="lstOrder" DisplayMemberPath="OrderID" ItemsSource="{Binding Source={StaticResource orders}}"/>
<ListBox Name="lstDate" DisplayMemberPath="OrderDate" ItemsSource="{Binding Source={StaticResource orders}}"/>

B.
<ListBox Name="lstOrder" DisplayMemberPath="OrderID" ItemsSource="{Binding Source={StaticResource orders}}"/>
<ListBox Name="lstDate" DisplayMemberPath="OrderDate" ItemsSource="{Binding ElementName=lstOrder, Path=OrderDate}"/>

C.
<ListBox Name="lstOrder" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="OrderID" ItemsSource="{Binding Source={StaticResource orders}}"/>
<ListBox Name="lstDate" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="OrderDate" ItemsSource="{Binding Source={StaticResource orders}}"/>

D.
<ListBox Name="lstOrder" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="OrderID" ItemsSource="{Binding Source={StaticResource orders}}"/>
<ListBox Name="lstDate" SynchronizedWithCurrentItem="True" DisplayMemberPath="OrderDate" ItemsSource="{Binding ElementName=lstOrder, Path=OrderDate}"/>



Leave a Reply 0

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