How do I get my custom WPF textbox to fill correctly?
- by Dan Ryan
I am trying to create a custom WPF textbox control that extends the standard textbox control but the extended textbox behaves differently when placed in control containers. Within my Window I have a stackpanel with a standard textbox and my extended textbox:
<StackPanel Margin="10">
<TextBox Height="21" />
<l:SearchTextBox Search="SearchTextBox_Search" Height="21" Margin="0, 10, 0, 0" SearchMode="Delayed" HorizontalAlignment="Left" />
</StackPanel>
The standard textbox stretches the length of the StackPanel whereas the custom textbox does not. How can I get the controls to behave the same? The styling for the custom textbox is shown below:
<Style x:Key="{x:Type UIControls:SearchTextBox}" BasedOn="{StaticResource {x:Type TextBox}}" TargetType="{x:Type UIControls:SearchTextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UIControls:SearchTextBox}">
<TextBox />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>