Peter
Peter

Reputation: 38455

WPF How to use the same template

Well how do i use a template on the TextBox and the PasswordBox atm i have 2 templates defined but thay contain exactly the same content....

Upvotes: 2

Views: 165

Answers (1)

Jobi Joy
Jobi Joy

Reputation: 50028

In the class hierarchy, both the controls have only "Control" class in common. So you can make the ControlTemplate for the 'Control' and assign to both. But if you need to have any TextBox/PasswordBox specific TemplateBindings in the template, then this wont work out for you. For example this bellow template will work for both the controls.

<ControlTemplate x:Key="template" TargetType="{x:Type Control}">
<Border BorderThickness="1,1,1,1" BorderBrush="#FF000000">
    <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>

Upvotes: 2

Related Questions