Reputation: 45
I have 2 textboxes which using AddItemTextBoxStyle:
<TextBox x:Name="txtItemA" Style="{StaticResource AddItemTextBoxStyle}"></TextBox>
<TextBox x:Name="txtItemB" Style="{StaticResource AddItemTextBoxStyle}"></TextBox>
Inside the AddItemTextBoxStyle (which is a style in Resource Dictionary), I have a tag property which sets the watermark text within the textbox:
<Style x:Key="AddItemTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource CustomTextBoxStyle}">
<Setter Property="Tag" Value="Type here" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<TextBlock Style="{StaticResource WaterMarkTextStyle}" x:Name="WaterMarkLabel" Text="{TemplateBinding Tag}" />
</ControlTemplate>
</Setter.Value>
</Setter.Property>
</Style>
By default, the watermark text is "Type here". However, if I want the watermark text to be different in the two textboxes, for example:
May I know how can I do this? Since the style is located in resource dictionary.
I try to search online but still unable to find a clue for it.
Upvotes: 0
Views: 48
Reputation: 27360
<TextBox x:Name="txtItemA" Style="{StaticResource AddItemTextBoxStyle}" Tag="Some wathermark" />
<TextBox x:Name="txtItemB" Style="{StaticResource AddItemTextBoxStyle}" Tag="Another watermarks" />
notice, that your style just sets default value of tag. Actual value is set in control instance and template binding takes the value from instance, not from style.
Upvotes: 2