Silverlight 4: How to find source UI element from contextmenu's menuitem_click?

Posted by funwithcoding on Stack Overflow See other posts from Stack Overflow or by funwithcoding
Published on 2010-04-20T19:19:25Z Indexed on 2010/04/20 20:43 UTC
Read the original article Hit count: 656

I have a datagrid and I added silverlight 4 toolkit contextmenu to textbox in datagrid as follows. When users right click on the textbox, contextmenu is being displayed. When users click the menu item with Header "Test", "MenuItem_Click" is getting executed. Now I want to access the textbox from the MenuItem_Click and modify its properties like background etc. Is there anyway to find textbox element(which is contextmenu's parent) from MenuItem_Click event?

It appears to me that I am missing something very simple.

<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
    <TextBox Text="{Binding AcctId}"
             Style="{StaticResource documentTextBoxStyle}"
             ToolTipService.ToolTip="Right Click to modify parameters" >
        <toolkit:ContextMenuService.ContextMenu >
            <toolkit:ContextMenu >
                <toolkit:MenuItem Header="Test" Click="MenuItem_Click"/>
            </toolkit:ContextMenu>
        </toolkit:ContextMenuService.ContextMenu>
    </TextBox>
</DataTemplate>

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about .NET