Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi my friends
i have a XAML file like follwoing:
<Grid>
        <Label x:Name="AttachmentNameLabel" Content="Attachment"
               Height="35" Width="80" Background="AliceBlue"
               BorderBrush="LightGray" BorderThickness="1.5" VerticalContentAlignment="Center">
            <Label.ContextMenu>
                <ContextMenu>
                    <MenuItem x:Name="PreviewMenuItem" Header="{Binding ElementName=AttachmentNameLabel,Path=Tag}"/>
                </ContextMenu>
            </Label.ContextMenu>
        </Label>
    </Grid>

but MenuItem.Header binding doesn't work. why?
please represent solution.
thanks
Posted
Updated 11-Sep-13 19:05pm
v2
Comments
rohith naik 12-Sep-13 8:09am    
Are you sure that the tag property is string ??

1 solution

Hello

Binding in ContextMenu doesn't work the way you think.

ContextMenu is something every wpf control possess therefore ContextMenu holds a property called PlacementTarget which as the name says identifies the target control where ContextMenu will be placed.

Now to your question. If you wish to use Binding in ContextMenu you will have to do it this way:

<stackpanel tag="this will be the header">
   <contextmenu>
           <menuitem>
               Header="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"
           </menuitem>
    </contextmenu>
</stackpanel>


See what I am trying to say? In my example PlacementTarget is the StackPanel.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900