Wpf Style: Binding to Child Property via ElementName

wpf, xaml

Solution

Got it working the DockPanel has a Border as Parent and with this Code I can set the Visibility of this Border to Hidden!

<Style TargetType="Border">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Child.Children[2].Name}"
                         Value="SearchTextBox">
                <Setter Property="Visibility" Value="Hidden"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

Possible improvement: Do not reference the TextBox per Index, iterate through childs...

Problem

I have an Application that gives me the Option to change the Application-Theme via a RessourceDictionary, meaning I can only use pure XAML. Now, what I want to do is hide a DockPanel, that does not have an ElementName, but it has a Child with an x:Name Property. ``` <Style TargetType="DockPanel"> <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self}, Path=Child.Visibility}"/> </Style> ``` With this Code I´m getting the first Child of the DockPanel, but I want to bind the value to the specific Child which has a unique ElementName. So not every DockPanel disappears, only the one that has a Child of Type e.g. "TextBox" with an Elementname of "MyTextBox". Anybody has an Idea how to do that? Thanks ;-)

Original source