binding a command inside a listbox item to a property on the viewmodel parent

后端 未结 7 2111
北海茫月
北海茫月 2020-12-15 18:42

I\'ve been working on this for about an hour and looked at all related SO questions.

My problem is very simple:

I have HomePageVieModel:

Home         


        
7条回答
  •  鱼传尺愫
    2020-12-15 19:26

    Well, it's a little bit late, I know. But I have only recently faced the same problem. Due to architectural reasons I decided to use a static viewmodel locator instead of the dataContextSpy.

    
                
    
            
                
                    
                        
                            
                                
                            
                        
                    
                
            
        
    
    

    The static viewmodel locator instantiates the view model:

    namespace MyNamespace
    {
        public static class ViewModelLocator
        {
            private static MyViewModelType myViewModel = new MyViewModelType();
            public static MyViewModelType MyViewModel 
            {
                get
                {
                    return myViewModel ;
                }
            }
        }
    }
    

    Using this workaround is another way to bind from a data template to a command that is in the viewmodel.

提交回复
热议问题