简体   繁体   中英

Adding a Control inside a TextBox?

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

在此处输入图片说明

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM