Which code segment should you use?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
You are defining a template as a resource in the application. The template will be applied to a button. You need to ensure that the template definition meets the following requirements:
* An image must appear to the left of the button.
* The content for the button must appear to the right of the button image.
* The template must be restricted only to button controls.
Which code segment should you use?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
You are defining a template as a resource in the application. The template will be applied to a button. You need to ensure that the template definition meets the following requirements:
* An image must appear to the left of the button.
* The content for the button must appear to the right of the button image.
* The template must be restricted only to button controls.
Which code segment should you use?

A.
<ControlTemplate x:Key="tpKey" TargetType="{x:Type Button}">
<StackPanel Orientation="Horizontal">
<Image Source="help.jpg" />
<ContentControl Content="{TemplateBinding Content}" />
</StackPanel>
</ControlTemplate>

B.
<ControlTemplate x:Key="tpKey">
<Button>
<StackPanel Orientation="Horizontal">
<Image Source="help.jpg" />
<ContentControl Content="Button.Content" />
</StackPanel>
</Button>
</ControlTemplate>

C.
<ControlTemplate x:Key="tpKey">
<Button>
<StackPanel Orientation="Horizontal">
<Image Source="help.jpg" />
<ContentControl Content="{TemplateBinding Button.Content}" />
</StackPanel>
</Button>
</ControlTemplate>

D.
<ControlTemplate x:Key="tpKey" TargetType="{x:Type Button}">
<Button>
<StackPanel Orientation="Horizontal">
<Image Source="help.jpg" />
<ContentControl Content="Parent.Content" />
</StackPanel>
</Button>
</ControlTemplate>



Leave a Reply 0

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