private static void OnDataContextDisposed(DynamicItemsSelectorView selectorView, object sender, EventArgs args)
 {
     selectorView.OnDataContextDisposed(sender);
 }
Example #2
0
        private static void DropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                if (selectorView == null)
                {
                    selectorView = new DynamicItemsSelectorView { Name = Guid.NewGuid().ToString() };
                    selectorView.SetBinding(MinWidthProperty, new Binding("MinWidth") { ElementName = "popup" });
                    selectorView.MaxHeight = 350; // May be we should find a better way to define max height
                }

                var contentControl = (FieldSingleCrossRef)d;

                if (selectorView.Parent != null && selectorView.Parent != contentControl.PopupContent)
                {
                    var control = selectorView.Parent as ContentControl;
                    if (control != null)
                    {
                        control.Content = null;
                    }
                }

                if (contentControl.PopupContent == null) return;

                contentControl.PopupContent.Content = selectorView;
                selectorView.Owner = contentControl;

                selectorView.Width = contentControl.ActualWidth;

                selectorView.InitPager();

                var updateBinding = false;

                if (selectorView.Parent != null && selectorView.Parent != contentControl.PopupContent)
                {
                    var container = selectorView.Parent as System.Windows.Controls.Primitives.Popup;

                    if (container != null)
                    {
                        container.Child = new ContentPresenter();
                    }

                    updateBinding = true;
                }

                selectorView.DataContext = contentControl.DataContext;

                if (updateBinding)
                {
                    var bindingExpression = selectorView.GetBindingExpression(WidthProperty);
                    selectorView.SetBinding(WidthProperty, bindingExpression.ParentBinding);

                    bindingExpression = selectorView.GetBindingExpression(MaxWidthProperty);
                    selectorView.SetBinding(MaxWidthProperty, bindingExpression.ParentBinding);

                    bindingExpression = selectorView.GetBindingExpression(MinWidthProperty);
                    selectorView.SetBinding(MinWidthProperty, bindingExpression.ParentBinding);
                }

                selectorView.ReBindPager();
            }
        }