0
我已經創建了一個自定義TextBox
,我想對此進行設計,併爲此TextBox
添加水印。我想在TextBox
爲空時添加水印,這種可見性只能從我的Style
設置。這是我的風格:文本框上的XAML控件模板,文本框上的數據查詢器
<Style TargetType="{x:Type textboxes:CustomTextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type textboxes:CustomTextBox}">
<Grid>
<Border Name="Border"
CornerRadius="2"
Padding="2"
Background="DeepPink"
BorderBrush="Green"
BorderThickness="1">
<Grid>
<ScrollViewer Margin="0"
x:Name="PART_ContentHost" />
<TextBlock IsHitTestVisible="False"
Text="WATERMARK!"
Foreground="White"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility"
Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=PART_ContentHost}"
Value="">
<Setter Property="Visibility"
Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style></TextBlock>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
預期的樣式應用,但我很難定義DataTrigger的TextBlock
內結合。我應該綁定什麼?
謝謝!回答upvoted和接受。 –