Which code segment should you include in the code-behind file?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
You include functionality in the application to troubleshoot the window behavior.
You need to display a list of UI elements at a position in the window that is decided by the mouse click. You also need to ensure that the list of elements is displayed in a message box.
Which code segment should you include in the code-behind file?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
You include functionality in the application to troubleshoot the window behavior.
You need to display a list of UI elements at a position in the window that is decided by the mouse click. You also need to ensure that the list of elements is displayed in a message box.
Which code segment should you include in the code-behind file?

A.
string controlsToDisplay = string.Empty;
private void Window_MouseDown( object sender, MouseButtonEventArgs e)
{
controlsToDisplay = ((UIElement)sender).ToString();
MessageBox.Show(controlsToDisplay);
}

B.
string controlsToDisplay = string.Empty;
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
for (int i = 0 ; i <= VisualChildrenCount – 1; ++i)
controlsToDisplay += GetVisualChild(i).ToString() + "rn" ;

MessageBox.Show(controlsToDisplay);
}

C.
string controlsToDisplay = string.Empty;

private void Window_MouseDown( object sender, MouseButtonEventArgs e)
{
Visual myVisual;

for (int i = 0; i <= VisualTreeHelper.GetChildrenCount((Visual)sender) – 1; ++i)
{
myVisual = (Visual)VisualTreeHelper.GetChild((Visual)sender, i);
controlsToDisplay += myVisual.GetType().ToString() + "rn" ;
}
MessageBox.Show(controlsToDisplay);
}

D.
string controlsToDisplay = string.Empty;
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
Point pt = e.GetPosition(this) ;
VisualTreeHelper.HitTest(this, null, new HitTestResultCallback(HitTestCallback), new PointHitTestParameters(pt));
MessageBox.Show(controlsToDisplay);
}

private HitTestResultBehavior HitTestCallback(HitTestResult result)
{
controlsToDisplay += result.VisualHit.GetType().ToString() + "rn" ;
return HitTestResultBehavior.Continue;
}



Leave a Reply 0

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