WPF binding multiple controls to different datacontexts

后端 未结 4 2008
不知归路
不知归路 2020-12-12 21:21

I have a scenario where I don\'t really know how to bind data to controls hosted in a UserControl to multiple datacontexts.

The data i want to bind comes from 2 clas

4条回答
  •  悲哀的现实
    2020-12-12 22:20

    I would maybe think about wrapping your user object in a seperate class then setting the DataContext properties of sub-panels that contain the data.

    For example:

    public class UserDataContext
    {
      public UserInfo UserInfo { get; set; }
      public UserExtendedInfo UserExtendedInfo { get; set; }
    }
    

    Then in your UserControl.xaml:

    
    
      
        
           
        
        
           
           
        
      
    
    

    This assumes that your UserInfo class has a property of Email

    and

    That your UserExtendedInfo class has a property of Locale and AboutMe

提交回复
热议问题