Exemplo n.º 1
0
        public MultiOrganizationSelector()
        {
            InitializeComponent();//注意UI上的属性赋值逻辑在InitializeComponent中执行,因此我将OrganizationSelectVM的构造置于InitializeComponent之后

            bool isLoaded = false;

            //以上说法错误
            //UI上的属性赋值逻辑在构造函数后执行,因此我将OrganizationSelectVM的构造置于Loaded事件中
            this.Loaded += delegate
            {
                if (!isLoaded)
                {
                    _dataContext = new OrganizationSelectVM(FilterCurrent, ShowAllLower, CanUserToggleShowAllLower, IsShowShopOnly);
                    var binding = new Binding();
                    binding.Source = _dataContext;
                    binding.Path   = new PropertyPath("ShowAllLower");
                    binding.Mode   = BindingMode.TwoWay;
                    this.SetBinding(MultiOrganizationSelector.ShowAllLowerProperty, binding);

                    //直接放在构造函数中不能反馈到绑定源,放在Loaded事件中可以,不知原因
                    SelectedOrganizationArray = _dataContext.DefaultOrSelectedOrganizations;//多处重复代码,只是为了客户端能收到通知,还有其它好的方式么?
                    isLoaded = true;
                }
            };
        }
 public MultiLowerOrganizationSelectWin(bool filterCurrent = true, IEnumerable <int> selectedIDs = null)
 {
     _dataContext     = new OrganizationSelectVM(filterCurrent);
     this.DataContext = _dataContext;
     InitializeComponent();
     if (selectedIDs != null)
     {
         //不放到Loaded中就不行(默认项未选中),只能说坑爹
         this.Loaded += delegate
         {
             _dataContext.SelectedIDs = selectedIDs;
             RadGridView1_Filtered(null, null);
         };
     }
 }
        public MultiOrganizationSelectWin(OrganizationSelectVM dataContext)
        {
            _dataContext     = dataContext;
            this.DataContext = _dataContext;
            InitializeComponent();

            //if (_dataContext.DefaultOrSelectedOrganizations.Count() != 0)
            //{
            //不放到Loaded中就不行(默认项未选中),只能说坑爹
            this.Loaded += delegate
            {
                RadGridView1_Filtered(null, null);
                _dataContext.PropertyChanged += _dataContext_PropertyChanged;
            };
            //}
        }