MVVM-Light, firing events from a button inside a data grid column template

后端 未结 3 1593
星月不相逢
星月不相逢 2021-02-06 02:43

MVVM light has been a pleasure to learn, but here I am stuck. The problem is event firing.

In the code below, one button the works and fires events. The other button doe

3条回答
  •  轮回少年
    2021-02-06 03:05

    Your data context is lost in the DataGrid DataGridTemplateColumn since the DataGrid.Columns isn't a dependency property. Because of this, you can't use element-to-element data binding from within your DataGridTemplateColumn.

    However, this is easily fixed thanks to MVVM Light Toolkit's ViewModelLocator.

    I don't know what your ViewModel is called, but assuming it is MainViewModel you can change your button binding to this:

    
        
            
                
            
        
    
    

提交回复
热议问题