private void OnDeleteValueField(object item)
        {
            if (OnDeleteFieldValue != null)
            {
                if (item is WriteOffValueItem)
                {
                    int lastIndex = ((WriteOffValueItem)item).Index;
                    RemoveValueItem((WriteOffValueItem)item);
                    if (this.FieldValuePanel.Children.Count == 0)
                    {
                        OnAddValueField(writeParent.Index == 0);
                    }
                    else
                    {
                        WriteOffValueItem wp = (WriteOffValueItem)this.FieldValuePanel.Children[0];
                        if (lastIndex == 0 && writeParent.Index == 0)
                        {
                            wp.showRowLabel(true);
                        }
                    }

                    if (OnDeleteFieldValue != null)
                    {
                        OnDeleteFieldValue(((WriteOffValueItem)item).WriteOffFieldValue);
                    }
                }
                //OnDeleteFieldValue(item);
            }
        }
 public void updateValue(WriteOffField writeOffField)
 {
     foreach (WriteOffFieldValue fieldValue in writeOffField.writeOffFieldValueListChangeHandler.Items)
     {
         if (fieldValue == null)
         {
             continue;
         }
         foreach (UIElement writeoffFieldValue in this.FieldValuePanel.Children)
         {
             if (writeoffFieldValue is WriteOffValueItem)
             {
                 WriteOffValueItem writeOffValue = (WriteOffValueItem)writeoffFieldValue;
                 if (writeOffValue.WriteOffFieldValue == null)
                 {
                     continue;
                 }
                 if (writeOffValue.WriteOffFieldValue.position == fieldValue.position)
                 {
                     writeOffValue.UpdateObject(fieldValue);
                     break;
                 }
             }
         }
     }
 }
        public void display()
        {
            FieldValuePanel.Children.Clear();
            int i = 0;

            if (fieldValueListChangeHandler == null)
            {
                WriteOffValueItem item = getPanel();
                bool isFirst           = !showLabel ? showLabel : true;
                AddValueItem(item, isFirst);
                return;
            }
            foreach (WriteOffFieldValue field in fieldValueListChangeHandler.Items)
            {
                WriteOffValueItem item = getPanel();
                item.WriteOffFieldValue = field;
                item.Index = i;
                if (this.isDateView)
                {
                    item.setDateView();
                }
                item.display(field);

                if (!showLabel)
                {
                    item.showRowLabel(false);
                }
                else
                {
                    if (i > 0)
                    {
                        item.showRowLabel(false);
                    }
                }

                this.FieldValuePanel.Children.Add(item);
                i++;
            }

            if (this.FieldValuePanel.Children.Count == 0)
            {
                WriteOffValueItem item = getPanel();
                item.Index = 0;
                if (!showLabel)
                {
                    item.showRowLabel(showLabel);
                }
                if (this.isDateView)
                {
                    item.setDateView();
                }
                else
                {
                    item.setIncrementalView(this.isIncremental);
                }
                this.FieldValuePanel.Children.Add(item);
            }
        }
        private WriteOffValueItem getPanel()
        {
            WriteOffValueItem witem = new WriteOffValueItem();

            witem.OnAddFieldValue    += OnAddValueField;
            witem.OnDeleteFieldValue += OnDeleteValueField;
            witem.ActivateFiedValue  += OnActivateValueField;
            witem.ItemChanged        += OnWriteOffValueChanged;
            return(witem);
        }
        public void RemoveValueItem(WriteOffValueItem valueItem)
        {
            this.FieldValuePanel.Children.Remove(valueItem);
            int i = 0;

            foreach (UIElement writeoff in this.FieldValuePanel.Children)
            {
                if (writeoff is WriteOffValueItem)
                {
                    ((WriteOffValueItem)writeoff).Index = i;
                    i++;
                }
            }
        }
        public void AddValueItem(WriteOffValueItem valueItem, bool isFirst = false)
        {
            int index = this.FieldValuePanel.Children.Count;

            valueItem.Index = index == 0 ? index : index - 1;
            if (isFirst)
            {
                valueItem.showRowLabel(true);
            }
            else
            {
                valueItem.showRowLabel(false);
            }
            OnActivateValueField(valueItem);
            this.FieldValuePanel.Children.Add(valueItem);
        }
 private void OnAddValueField(object item)
 {
     if (OnAddFieldValue != null)
     {
         WriteOffValueItem witem = getPanel();
         if (item is bool)
         {
             AddValueItem(witem, (bool)item);
         }
         else
         {
             AddValueItem(witem);
         }
         OnAddFieldValue(item);
     }
 }