This question向我展示瞭如何爲我的文本框添加水印文本。我試圖在我的項目中實現它,但它取代了我的TextBox的背景。如何添加背景到文本框提示橫幅
因爲我的面板具有不同的顏色,所以面板顏色通過文本框顯示。我如何正確設置?
我試圖將標籤的背景設置爲白色,但由於沒有拉伸,所以不起作用。
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="Uniform">
<VisualBrush.Visual>
<!-- set the background to white -->
<Label Content="Search" Foreground="LightGray" Background="White"/>
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Static sys:String.Empty}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
這給出了以下:
但設置拉伸填充給出了這樣的結果與拉伸文本:
是一種[水印文本](http://stackoverflow.com/a/21673718/2998271)你想實現?沒有? – har07
是的。我剛剛發現這篇文章,它似乎是最簡單明瞭的解決方案,很容易理解。是的,我可以下載或重新創建更多選項,但我只是對這個特定的帖子感興趣。 – Marnix