public void LoadFrom(HoleCardRangeDefinition def) { if (def == null) { this.Name = string.Empty; this.Description = string.Empty; this.DefaultRange = float.NaN; this.DefaultVariation = float.NaN; this.Hands = null; } else { this.Name = def.Name; this.Description = def.Description; this.DefaultRange = def.DefaultRange; this.DefaultVariation = def.DefaultVariation; ObservableCollection<HandDefinitionModel> defs = new ObservableCollection<HandDefinitionModel>(); foreach (HandDefinition handDef in def.Hands.OrderByDescending(h => h.Value)) { HandDefinitionModel hand = new HandDefinitionModel(handDef); hand.RearrangeRanks = new HandDefinitionModel.RearrangeRanksHandler(RearrangeRanks); defs.Add(hand); } this.Hands = defs; } }
/// <summary> /// re-arrange ranks from start drag to new listing /// </summary> /// <param name="startDragHand"></param> /// <param name="newListingHand"></param> public void RearrangeRanks(HandDefinitionModel startDragHand, HandDefinitionModel newListingHand) { int oldIndex = Hands.IndexOf(startDragHand); int newIndex = Hands.IndexOf(newListingHand); startDragHand.Value = newListingHand.Value; // replace start rank value to the new rank value int indexOffset = (newIndex > oldIndex) ? 1 : -1; int currentIndex = oldIndex; // update from next of the start rank value to the new rank value while (currentIndex != newIndex) { currentIndex = currentIndex + indexOffset; Hands[currentIndex].Value = Hands[currentIndex].Value + indexOffset; } Hands.Move(oldIndex, newIndex); InvalidateProperty(HandRangeDefinitionModel.HandsProperty); }
/// <summary> /// re-arrange ranks with current hand's rank changed /// </summary> /// <param name="hand"></param> protected void RearrangeRanks(HandDefinitionModel hand) { HandDefinitionModel startDragHand = hand; HandDefinitionModel newListingHand = Hands[169 - (int)(hand.Value)]; RearrangeRanks(startDragHand, newListingHand); }
protected void SetModel(object sender, DependencyPropertyChangedEventArgs e) { Model = DataContext as HandDefinitionModel; if (Model == null) return; }