Context Menu SourceControl Error
- by developer
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??