WPF: How to set bool to true from DataTemplate for Button?

前端 未结 2 1360
刺人心
刺人心 2021-01-28 15:52

I know it is possible to do this by working with ICommand, but since this is the only place in my whole project where this is needed, I am asking myself, if there is maybe a bet

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 16:34

    You could use the Click eventhandler of the Button. Then you don't need any Commands.

    private void bt_Delete_Click(object sender, RoutedEventArgs e)
    {
        var btn = sender as Button;
        YourClass dc = btn.DataContext as YourClass;
        dc.IsToDelete = true;
    }
    

    I don't really like this solution, but I think, it would work.

提交回复
热议问题