As we want to customize the template of the custom control to have a proper template binding, perform the following steps:
- Open the Generic.xaml file, which is present under the Themes folder of the project.
- Now, scroll down to the definition of the ControlTemplate as we need to customize the look and feel of it.
- Search for the TextBox control named PART_TextBox, and set its Background, BorderBrush, BorderThickness, and Foreground properties to have a binding with the control's default properties.
- Similarly, set the Background and Foreground property of the button (PART_Button) to the same properties of the control, by using template binding. Here's the complete code of the modified control template:
<ControlTemplate TargetType="{x:Type local:SearchControl}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> ...