Using the parent's DataContext (WPF - Dynamic Menu Command Binding)

后端 未结 4 768
一个人的身影
一个人的身影 2020-12-25 12:50

I looked over this web and google and the solutions didn\'t work for me.

I have a command on the ViewModel of a UserControl. Well, The usercontrol have a ItemsContro

4条回答
  •  庸人自扰
    2020-12-25 12:57

    Ok, then what about modifying your data item class so that it has a property referencing to the whole model view?

    If your ItemsSource is of type ObservableCollection then modify DataItem type like this:

    public class DataItem
    {
        public BusinessObject Value { get; set; }
    
        private ModelView modelView;
    
        public ModelView ModelView
        {
            get
            {
                return modelView;
            }
        }
    
        public DataItem(ModelView modelView)
        {
            this.modelView = modelView;
        }
    }
    

提交回复
热议问题