Which two tasks should you perform?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The XAML page for the application will display employee information from an XML file. The following code fragment is an excerpt from the XML file.
<Employee>
<Manager FirstName="Adam" LastName="Barr" Photo="E1.jpg"/>
<Engineer FirstName="Mu" LastName="Han" Photo="E2.jpg"/>

</Employee>

The file is exposed as a resource named employees.
You add the following templates under the Window.Resources element.
<DataTemplate x:Key="Manager">
<Image Source="{Binding XPath=@Photo}" Height="50"/>
</DataTemplate>
<DataTemplate x:Key="Engineer">
<Image Source="{Binding XPath=@Photo}" Height="40"/>
</DataTemplate>

You need to ensure that the selection of templates is dependent on the XML element being rendered.
Which two tasks should you perform? (Each correct answer presents part of the solution.)

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The XAML page for the application will display employee information from an XML file. The following code fragment is an excerpt from the XML file.
<Employee>
<Manager FirstName="Adam" LastName="Barr" Photo="E1.jpg"/>
<Engineer FirstName="Mu" LastName="Han" Photo="E2.jpg"/>

</Employee>

The file is exposed as a resource named employees.
You add the following templates under the Window.Resources element.
<DataTemplate x:Key="Manager">
<Image Source="{Binding XPath=@Photo}" Height="50"/>
</DataTemplate>
<DataTemplate x:Key="Engineer">
<Image Source="{Binding XPath=@Photo}" Height="40"/>
</DataTemplate>

You need to ensure that the selection of templates is dependent on the XML element being rendered.
Which two tasks should you perform? (Each correct answer presents part of the solution.)

A.
Add the following ListBox control to the XAML code fragment for the window.
<ListBox ItemsSource="{Binding Source={StaticResource employees}, XPath=/Employee/*}"/>

B.
Add the following template to the Windows.Resources element.
<HierarchicalDataTemplate x:Key="Employee" ItemsSource="{Binding XPath=/Employee/*}">
<TextBlock Text="Employees" FontSize="20" />
</HierarchicalDataTemplate>

C.
Add the following template to the Windows.Resources element.
<HierarchicalDataTemplate x:Key="Employee" ItemsSource="{Binding XPath=*}">
<TextBlock Text="Employees"FontSize="20" />
</HierarchicalDataTemplate>

D.
Add the following ListBox control to the XAML code fragment for the page.
<ListBox ItemsSource="{Binding Source={StaticResource employees}, XPath=/Employee/*}">
<ListBox.ItemTemplateSelector>
<local:EmployeeTemplateSelector xmlns:local="clr-namespace:AppNamespace"/>
</ListBox.ItemTemplateSelector>
</ListBox>

E.
Add the following class to the code-behind file.
public class EmployeeTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
XmlElement data = (XmlElement)item;
return (DataTemplate)(((FrameworkElement)container).FindResource(data.LocalName));
}
}



Leave a Reply 0

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