Context Menu SourceControl Error

Posted by developer on Stack Overflow See other posts from Stack Overflow or by developer
Published on 2010-03-11T18:51:14Z Indexed on 2010/03/11 18:54 UTC
Read the original article Hit count: 204

Filed under:

Hi All, I am trying to use contextmenu in my textbox control and I want to bind the textbox value to the value selected in context menu,below is my code

<Window.CommandBindings>
    <CommandBinding Command="local:MyPanel.ChangeTextboxValue" Executed="ChangeTextboxValue_Executed"/>
</Window.CommandBindings>

  CODE-BEHIND

public static RoutedUICommand ChangeTextboxValue = new RoutedUICommand    ("ChangeTextboxValue", "ChangeTextboxValue", typeof(MyPanel));

 private void ChangeTextboxValue_Executed(object sender, ExecutedRoutedEventArgs e)
    { 
        string oldvalue = Convert.ToString(e.Parameter);

        (((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox).Text = oldvalue;        }

oldvalue is the value I want the textbox controls value to change to. I am trying to use above code but it gives me the error, 'Object reference not set to an instance of object'. I tried to debug the app and I get ContextMenu as null.. .Any ideas why??

© Stack Overflow or respective owner

Related posts about wpf-controls