Bind Dependency Property, defined in Code-Behind, through Xaml to a Property in the DataContext of a UserControl

前端 未结 1 1120
礼貌的吻别
礼貌的吻别 2021-01-25 06:20

I want to use code similar to that found here. The issue I\'m having is that I\'d like to extend it to allow the value set in the XAML to use {Binding PropertyOfViewModel}

1条回答
  •  时光取名叫无心
    2021-01-25 07:03

    If I understood everything correctly then what you need is a standard MVVM scenario and standard bindings.

    It can be done either like this:

    
    
    

    Or like this:

    
      
        
      
    
    

    Update: In response to the code of your UserControl you've shown...

    What you are doing is placing a control inside itself, which obviously will give you a StackOverflow exception. You don't need to define a ContentTemplate inside UserControl. You can just place the content directly as a child element:

    
    
        
            
                
                    
                        
                        
                        
                    
                
    
                
                    
                        
                        
                        
                    
                
            
        
    
        
                
        
        
                
        
    
       
          
    
    

    0 讨论(0)
提交回复
热议问题