Bastien Vandamme
Bastien Vandamme

Reputation: 18465

Binding to the name of a parent element

sorry for this probably simple question but I don't understand how binding works. In the following XAML code I would like to pass my rectangle name as command parameter. I would like to pass "Color01".

    <Rectangle x:Name="Color01" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="10,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseDown">
                <i:InvokeCommandAction Command="{Binding MyCommand}" CommandParameter="{Binding ???}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Rectangle>

What should I write in my binding ???

Upvotes: 1

Views: 1018

Answers (1)

Rohit Vats
Rohit Vats

Reputation: 81253

You can pass Name using RelativeSource markup extension:

CommandParameter="{Binding Name, RelativeSource={RelativeSource
                                 Mode=FindAncestor, AncestorType=Rectangle}}"

Upvotes: 3

Related Questions