For an Placeholder/Watermark in an TextBox I use this Style get that to work:
<Style x:Key="placeHolder" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid Margin="15 0 15 0">
<TextBox Text="{Binding Path=Text,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
x:Name="textSource" TextWrapping="Wrap"
BorderBrush="Red" AcceptsReturn="True"
BorderThickness="0"
Background="Transparent"
Panel.ZIndex="2" />
<TextBox Text="{TemplateBinding Tag}" TextWrapping="Wrap" Background="{TemplateBinding Background}" Panel.ZIndex="1">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="Transparent"/>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="" />
<Condition Binding="{Binding printcontrol}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="LightGray"/>
<Setter Property="Visibility" Value="Hidden"/>
</MultiDataTrigger>
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
<Setter Property="Foreground" Value="LightGray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But now I need to use an RichTextBox and now that doesn't work for that so what Ive tried is something like that:
<RichTextBox x:Name="Placeholder" Height="20" IsHitTestVisible="True" VerticalAlignment="Top" Margin="0,20,298.8,0" Foreground="DarkGray" HorizontalAlignment="Right" Width="214">
<FlowDocument>
<Paragraph>
<Run Foreground="Black">
<Run.Style>
<Style TargetType="{x:Type Run}">
<Setter Property="Foreground" Value="Transparent"/>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="" />
<Condition Binding="{Binding printcontrol}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="LightGray"/>
<Setter Property="FontSize" Value="0.004"/>
</MultiDataTrigger>
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
<Setter Property="Foreground" Value="LightGray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Run.Style>
</Run>
</Paragraph>
</FlowDocument>
</RichTextBox>
But that didn't work. Has someone an Idea how to get Placeholder RichTextBox
?
End Result should be something like that: