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

后端 未结 3 1590
星月不相逢
星月不相逢 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:22

    This solution only works for static view models. check out Dan Whalin's page out for an alternative answer. http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx

    You can create a resource like so (don't forget your reference):

    
         
    
    

    or

    
        
    
    

    Use in control like so:

    
    
        
            
        
    
    

    ViewModel Define RelayCommand:

    public RelayCommand MyCommand { get; set; }
    
    
    

    Set RelayCommand in Constructor:

    MyCommand = new RelayCommand((e) =>
            {
                if (e != null && e is int)
                {
                    int varName = int.Parse(e.ToString());
    
                    //DoSomething...
                }
            });
    
        

    提交回复
    热议问题