Get DataContext from TextBlock MouseDown

前端 未结 2 363
攒了一身酷
攒了一身酷 2021-01-03 11:57

Bound column in a ListView GridView

How to get the DataSource in a MouseDown event


               


        
2条回答
  •  北海茫月
    2021-01-03 12:40

    For anyone still having problems, this works fine as well.

    private void MenuItem_Click(object sender, RoutedEventArgs e)
    {
        var baseobj = sender as FrameworkElement;
        var myObject = baseobj.DataContext as (Object you expect);
    
        // Example: var myObject = baseobj.DataContext as Dog;
        // myObject.Bark();
    }
    

提交回复
热议问题