0

I have got a style as follows.

<TextBox HorizontalContentAlignment="Center" Text="{Binding IpAddress, Mode=TwoWay}" ToolTip="Ip Address of camera">
                    <TextBox.Style>
                        <Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
                            <Style.Resources>
                                <VisualBrush x:Key="CueBannerBrush" AlignmentX="Center"  AlignmentY="Center" Stretch="None">
                                    <VisualBrush.Visual>
                                        <Label Content="Camera Ip Address" Foreground="Gray" Opacity="0.5" FontStyle="Italic" />
                                    </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>     

And I had kept it as a resource dictionary in a Skin.xaml file to be re-used as explained in the answer here.

But now I want the Content="Camera Ip Address" (the 7th line in the style) to be different for each textbox that I apply the style to. I saw SO answers this and this. These SO answers are suggesting the BasedOn attribute, but I am not sure how to apply this to my case. My case seems to be many levels deep. Can someone please suggest me how to achieve this.

Basically what I want is, for one textbox that I apply the Content should be Camera Ip Address, while for another textbox I want this content to be Camera Login. How do I achieve this?

Community
  • 1
  • 1
VivekDev
  • 20,868
  • 27
  • 132
  • 202

1 Answers1

1

You can set the content of that inner Label to the Tag property of the TextBox and then display it in the Label.

Like so:

<TextBox Tag="Whatever you want">
    <TextBox.Style>
        <Style TargetType="TextBox">
            <Style.Resources>
                <VisualBrush x:Key="CueBannerBrush">
                     <VisualBrush.Visual>
                         <Label Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TextBox},Path=Tag,Mode=OneWay" />
                     </VisualBrush.Visual>
                </VisualBrush>
            </Style.Resources>
        </Style>
    </TextBox.Style>
</TextBox>
GregorMohorko
  • 2,739
  • 2
  • 22
  • 33