How do I get my custom WPF textbox to fill correctly?

Posted by Dan Ryan on Stack Overflow See other posts from Stack Overflow or by Dan Ryan
Published on 2010-05-05T07:47:49Z Indexed on 2010/05/05 8:08 UTC
Read the original article Hit count: 581

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>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-controls