文本框中的多个元素,不会影响对齐 [英] Multiple elements in Textbox without effecting alignment
问题描述
嘿,
我有一个文本框应该有一个居中的文本和一个右侧的图标,而不会让中心向左移动。
I've got a Textbox that should have a Text centered in it and a Icon on the right side of it without the center getting moved to the left.
我在文本框中尝试了一个网格,但是当我插入图标时会移动文本。尝试了InlineUIContainer,但这对我也没有用。
I've tried a Grid within the Textbox but that moves the Text when i insert the icon. Tried InlineUIContainer aswell but that didn't work for me either.
遗憾的是我无法发布图片,但我希望你明白我的意思。
Sadly i can not post Images yet i hope you get what i mean.
提前致谢
Jan
推荐答案
嘿,
Hey,
我有一个文本框应该有一个居中的文本和一个右侧的图标,中心不会向左移动。
I've got a Textbox that should have a Text centered in it and a Icon on the right side of it without the center getting moved to the left.
我在文本框中尝试了一个网格,但是当我插入图标时会移动文本。尝试了InlineUIContainer,但这对我也没有用。
I've tried a Grid within the Textbox but that moves the Text when i insert the icon. Tried InlineUIContainer aswell but that didn't work for me either.
遗憾的是我无法发布图片,但我希望你明白我的意思。
Sadly i can not post Images yet i hope you get what i mean.
提前致谢
Jan
您好Hasok,
我不确定您遇到了什么问题,但是您可以查看以下代码,看看它是否可以解决您的问题。
I am not sure what problem you are having, but you can take a look the following code, and let see if it can resolved your issue.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox
Width="300"
Height="100"
Text="Test">
<TextBox.Template>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBox
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Text="{TemplateBinding Text}" />
<Image
Width="30"
Height="30"
Margin="0,0,5,0"
HorizontalAlignment="Right"
Source="\Images\1.jpg" />
</Grid>
</ControlTemplate>
</TextBox.Template>
</TextBox>
</Grid>
最好的问候,
Cherry
这篇关于文本框中的多个元素,不会影响对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!