[英]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?
不使用richTextBox怎么办?
Thanks 谢谢
TextBox is not a container, and therefore hasn't children. TextBox不是容器,因此没有子级。 Perhaps try wrapping the TextBox in a container object?
也许尝试将TextBox包装在容器对象中?
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. 重新设置样式并重新绑定,最适合您的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.