WPF Context menu doesn't bind to right databound item

前端 未结 7 1334
青春惊慌失措
青春惊慌失措 2020-12-08 11:03

I have a problem when binding a command in a context menu on a usercontrol that is on a tab page. The first time I use the menu (right-click on the tab) it works great, but

7条回答
  •  情书的邮戳
    2020-12-08 12:05

    I prefer another solution. Add context menu loader event.

     
         
     
    

    Assign data context within the event.

    private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
    {
        (sender as ContextMenu).DataContext = this; //assignment can be replaced with desired data context
    }
    

提交回复
热议问题