1

i am trying to make a usercontrol that will emulate a regular textbox, but has tags. Something along the lines of this:

enter image description here

but i am having trouble...I tried to do this:

<TextBox> 
    <Border/>
</TextBox>

but that will not work. How would i do this, without using a richTextBox?

Thanks

6
  • I believe you need to create a custom style for the TextBox. Unfortunately it is not trivial. Commented Mar 27, 2013 at 23:10
  • how would i make a custom style like that? Commented Mar 27, 2013 at 23:11
  • Try this to help you get started codeproject.com/Tips/139563/Custom-WPF-TextBox-Style. It isn't exactly what you need but hopefully points you in the right direction Commented Mar 27, 2013 at 23:13
  • Another example codeproject.com/Articles/487972/… Commented Mar 27, 2013 at 23:14
  • i am not completely sure that the styling will effect the controls ability to contain custom controls Commented Mar 27, 2013 at 23:15

1 Answer 1

1

TextBox is not a container, and therefore hasn't children. Perhaps try wrapping the TextBox in a container object?

Some example code to get you started:

    <Border Grid.Row="0" BorderBrush="#FF808080" Background="#FFFFFFFF" >
        <DockPanel>
            <ItemsControl DockPanel.Dock="Left" ItemsSource="{Binding Tags}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border BorderBrush="#FF000000" BorderThickness="1" Margin="3">
                            <DockPanel>
                                <Button DockPanel.Dock="Right" Content="X" />
                                <TextBlock Text="{Binding}" Margin="3" />
                            </DockPanel>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <TextBox BorderThickness="0" Text="{Binding Text}" VerticalContentAlignment="Center" />
        </DockPanel>
    </Border>

Restyle and rebind however best fits into your solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.