gpt4 book ai didi

带有图像的 WPF 文本框

转载 作者:行者123 更新时间:2023-12-04 22:33:42 29 4
gpt4 key购买 nike

我正在做一个WPF登录界面。在我的登录面板中,我有一个登录 TextBoxPasswordBox .如下图第一张所示,登录文本框中有一个小人类标志,密码框中有一个锁。我将图像设置为文本框背景,然后当我尝试在登录框中插入一些单词时,这些单词将覆盖人类 Logo (图像 B)。有什么建议可以使它正确吗?

我的 XAML:

 <TextBox Width="380" Height="25" HorizontalAlignment="Center"  Foreground="WhiteSmoke" BorderBrush="Transparent" >
<TextBox.Background>
<ImageBrush ImageSource="/icon/user_login.png" AlignmentX="Left" Stretch="None"></ImageBrush>
</TextBox.Background>
</TextBox>

图片一:

enter image description here

图片 B:

enter image description here

最佳答案

我的建议是您替换每个 Textbox'sDockPanel .其中他们每个人都有一个 Image作为最左边的项目和 Textbox作为最正确的。然后将图像分别设置为用户和锁定。然后设置Textbox的背景和 Images到透明。然后你可以在 DockPanel 上设置任何你想要的样式。 .

编辑 1 - 从工作示例中复制粘贴

代码:

<DockPanel>
<Button BorderThickness="0" DockPanel.Dock="Left" HorizontalAlignment="Right" Height="28" Width="23">
<DynamicResource ResourceKey="SearchBar"/>
</Button> 'This is a button, because I have a custom Style which I am using which makes all the borders go away. And also because I use it to clear the field.
<TextBox Text="Search..." FontSize="16" HorizontalAlignment="Stretch" Background="Transparent"/>
</DockPanel>

图片:

enter image description here

通过不设置 DockPanel.Dock第二个项目的属性,我告诉它延伸到 DockPanel 的其余部分.如有其他疑问,请告诉我。如果你复制粘贴上面的内容,它可能看起来不一样,因为我剪掉了不相关的部分。

关于带有图像的 WPF 文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13927364/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com