public Layout() { Loaded += (sender, args) => LoadedLayouts.Add(this); Unloaded += (sender, args) => LoadedLayouts.Remove(this); CommandBindings.Add(new CommandBinding(UnfloatItemCommand, UnfloatExecuted, CanExecuteUnfloat)); CommandBindings.Add(new CommandBinding(MaximiseFloatingItem, MaximiseFloatingItemExecuted, CanExecuteMaximiseFloatingItem)); CommandBindings.Add(new CommandBinding(CloseFloatingItem, CloseFloatingItemExecuted, CanExecuteCloseFloatingItem)); CommandBindings.Add(new CommandBinding(RestoreFloatingItem, RestoreFloatingItemExecuted, CanExecuteRestoreFloatingItem)); CommandBindings.Add(new CommandBinding(TileFloatingItemsCommand, TileFloatingItemsExecuted)); CommandBindings.Add(new CommandBinding(TileFloatingItemsCommand, TileFloatingItemsExecuted)); CommandBindings.Add(new CommandBinding(TileFloatingItemsVerticallyCommand, TileFloatingItemsVerticallyExecuted)); CommandBindings.Add(new CommandBinding(TileFloatingItemsHorizontallyCommand, TileFloatingItemsHorizontallyExecuted)); //TODO bad bad behaviour. Pick up this from the template. _floatingItems = new DragablzItemsControl { ContainerCustomisations = new ContainerCustomisations( GetFloatingContainerForItemOverride, PrepareFloatingContainerForItemOverride, ClearingFloatingContainerForItemOverride) }; var floatingItemsSourceBinding = new Binding("FloatingItemsSource") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemsSourceProperty, floatingItemsSourceBinding); var floatingItemsControlStyleBinding = new Binding("FloatingItemsControlStyle") { Source = this }; _floatingItems.SetBinding(StyleProperty, floatingItemsControlStyleBinding); var floatingItemTemplateBinding = new Binding("FloatingItemTemplate") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemTemplateProperty, floatingItemTemplateBinding); var floatingItemTemplateSelectorBinding = new Binding("FloatingItemTemplateSelector") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemTemplateSelectorProperty, floatingItemTemplateSelectorBinding); var floatingItemContainerStyeBinding = new Binding("FloatingItemContainerStyle") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemContainerStyleProperty, floatingItemContainerStyeBinding); var floatingItemContainerStyleSelectorBinding = new Binding("FloatingItemContainerStyleSelector") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemContainerStyleSelectorProperty, floatingItemContainerStyleSelectorBinding); }
//really absurd way of fixing order issue public void ReorderSkillContainer(DragablzItemsControl container, SynchronizedObservableCollection <FixedSkillCooldown> collection) { var positions = new Dictionary <int, double>(); //index, X for (var i = 0; i < container.Items.Count; i++) { var curr = container.ItemContainerGenerator.ContainerFromIndex(i) as UIElement; var p = curr.TransformToAncestor(this).Transform(new Point(0, 0)); positions.Add(i, p.X); } var needsReorder = false; for (var j = 0; j < positions.Count; j++) { if (j + 1 == positions.Count) { continue; } if (positions[j] > positions[j + 1]) { needsReorder = true; break; } } if (!needsReorder) { return; } container.ItemsSource = null; container.ItemsSource = collection; }
public Layout() { Loaded += (sender, args) => LoadedLayouts.Add(this); Unloaded += (sender, args) => LoadedLayouts.Remove(this); CommandBindings.Add(new CommandBinding(UnfloatCommand, UnfloatExecuted)); _floatingItems = new DragablzItemsControl( GetFloatingContainerForItemOverride, PrepareFloatingContainerForItemOverride, ClearingFloatingContainerForItemOverride); var floatingItemsSourceBinding = new Binding("FloatingItemsSource") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemsSourceProperty, floatingItemsSourceBinding); var floatingItemsControlStyleBinding = new Binding("FloatingItemsControlStyle") { Source = this }; _floatingItems.SetBinding(StyleProperty, floatingItemsControlStyleBinding); var floatingItemTemplateBinding = new Binding("FloatingItemTemplate") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemTemplateProperty, floatingItemTemplateBinding); var floatingItemTemplateSelectorBinding = new Binding("FloatingItemTemplateSelector") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemTemplateSelectorProperty, floatingItemTemplateSelectorBinding); var floatingItemContainerStyeBinding = new Binding("FloatingItemContainerStyle") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemContainerStyleProperty, floatingItemContainerStyeBinding); var floatingItemContainerStyleSelectorBinding = new Binding("FloatingItemContainerStyleSelector") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemContainerStyleSelectorProperty, floatingItemContainerStyleSelectorBinding); }
private void Add(DragablzItemsControl dragablzItemsControl) { //the items control does not keep your source collection sorted as per what is on screen. //this causes too much implementation complexity, and creates a dog-chasing-its-own tail scenario. //so, you can use a PositionMonitor (defined in MainWindow.xaml) to monitor rendering order. //However, if you want to add a new item to your underlying source (where the sort is not applied) //then you can use the .AddToSource() method which allows to to insert and control the rendered sort of the new item. //if you're in MVVM you might not consider this "pure", but hey, sometimes you gotta compromise. In this example //I pass in the dragablzItemsControl from the Button CommandParameter. You _could_ implement a custom IItemsOrganiser //to go full MVVM...but personally I would consider this overkill for minimal gain. var newItem = Data.Max() + 1; dragablzItemsControl.AddToSource(newItem, AddLocationHint.Last); //your source collection will have the new item added (but sort is mnever applied, for that use dragablzItemsControl.PositionMonitor, example also in the XAML). Debug.Assert(Data.Contains(newItem)); }
public Layout() { Loaded += (sender, args) => LoadedLayouts.Add(this); Unloaded += (sender, args) => LoadedLayouts.Remove(this); CommandBindings.Add(new CommandBinding(UnfloatItemCommand, UnfloatExecuted, CanExecuteUnfloat)); CommandBindings.Add(new CommandBinding(MaximiseFloatingItem, MaximiseFloatingItemExecuted, CanExecuteMaximiseFloatingItem)); CommandBindings.Add(new CommandBinding(CloseFloatingItem, CloseFloatingItemExecuted, CanExecuteCloseFloatingItem)); CommandBindings.Add(new CommandBinding(RestoreFloatingItem, RestoreFloatingItemExecuted, CanExecuteRestoreFloatingItem)); CommandBindings.Add(new CommandBinding(TileFloatingItemsCommand, TileFloatingItemsExecuted)); CommandBindings.Add(new CommandBinding(TileFloatingItemsCommand, TileFloatingItemsExecuted)); CommandBindings.Add(new CommandBinding(TileFloatingItemsVerticallyCommand, TileFloatingItemsVerticallyExecuted)); CommandBindings.Add(new CommandBinding(TileFloatingItemsHorizontallyCommand, TileFloatingItemsHorizontallyExecuted)); //TODO bad bad behaviour. Pick up this from the template. _floatingItems = new DragablzItemsControl { ContainerCustomisations = new ContainerCustomisations( GetFloatingContainerForItemOverride, PrepareFloatingContainerForItemOverride, ClearingFloatingContainerForItemOverride) }; var floatingItemsSourceBinding = new Binding("FloatingItemsSource") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemsSourceProperty, floatingItemsSourceBinding); var floatingItemsControlStyleBinding = new Binding("FloatingItemsControlStyle") { Source = this }; _floatingItems.SetBinding(StyleProperty, floatingItemsControlStyleBinding); var floatingItemTemplateBinding = new Binding("FloatingItemTemplate") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemTemplateProperty, floatingItemTemplateBinding); var floatingItemTemplateSelectorBinding = new Binding("FloatingItemTemplateSelector") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemTemplateSelectorProperty, floatingItemTemplateSelectorBinding); var floatingItemContainerStyeBinding = new Binding("FloatingItemContainerStyle") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemContainerStyleProperty, floatingItemContainerStyeBinding); var floatingItemContainerStyleSelectorBinding = new Binding("FloatingItemContainerStyleSelector") { Source = this }; _floatingItems.SetBinding(ItemsControl.ItemContainerStyleSelectorProperty, floatingItemContainerStyleSelectorBinding); }
public override void OrganiseOnDragCompleted(DragablzItemsControl requestor, Size measureBounds, IEnumerable <DragablzItem> siblingItems, DragablzItem dragItem) { DragCompleted?.Invoke(); base.OrganiseOnDragCompleted(requestor, measureBounds, siblingItems, dragItem); }
public override Point ConstrainLocation(DragablzItemsControl requestor, Size measureBounds, Point itemCurrentLocation, Size itemCurrentSize, Point itemDesiredLocation, Size itemDesiredSize) { return(base.ConstrainLocation(requestor, new Size(measureBounds.Width + 10000, measureBounds.Height), itemCurrentLocation, itemCurrentSize, itemDesiredLocation, itemDesiredSize)); }