1

Trying to bind to the Tag property of a textbox from a datatrigger, but doesnt seem to get the binding corrrect

Partial xaml

<TextBox Grid.Column="2" Tag="Enter password" Text="{Binding UserName, Mode=TwoWay}"  Name="textBox1" Width="200" Height="25" HorizontalAlignment="Left" >
    <TextBox.Style>
        <Style TargetType="TextBox">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="">
                    <Setter Property="Background">
                        <Setter.Value>
                            <VisualBrush Stretch="None">
                                <VisualBrush.Visual>
                                    <TextBlock Text="{Binding 
                    RelativeSource={RelativeSource 
                        Mode=FindAncestor, 
                        AncestorType={x:Type TextBox}}, 
                        Path=Tag}"
                               Foreground="Gray"/>
                                </VisualBrush.Visual>
                            </VisualBrush>
                        </Setter.Value>
                    </Setter>

Its the part

<TextBlock Text="{Binding 
                        RelativeSource={RelativeSource 
                            Mode=FindAncestor, 
                            AncestorType={x:Type TextBox}}, 
                            Path=Tag}"

that is not working. I have tried a couple of solutions, but textbox is always ending up empty.

klashagelqvist
  • 1,251
  • 2
  • 26
  • 52
  • 1
    See this post: http://stackoverflow.com/questions/3639537/wpf-bind-to-parent-property-from-within-nested-element-using-style – SDK Mar 18 '12 at 10:59

0 Answers0