public CellPropertiesControl()
        {
            InitializeComponent();

            PropertiesCtrl = new PropertiesListControl();
            TupleCtrl = new CellTupleControl();

            TabItem PropertiesTab = new TabItem();
            PropertiesTab.Header = Localization.Properties;
            PropertiesTab.Style = TabCtrl.Resources["TabControlOutputItem"] as Style;
            PropertiesTab.Content = PropertiesCtrl;

            TabItem TupleTab = new TabItem();
            TupleTab.Header = Localization.Tuple;
            TupleTab.Style = TabCtrl.Resources["TabControlOutputItem"] as Style;
            TupleTab.Content = TupleCtrl;

            TabCtrl.TabCtrl.Items.Add(PropertiesTab);
            TabCtrl.TabCtrl.Items.Add(TupleTab);

            TupleCtrl.HierarchyColumn.Width = PropertiesCtrl.PropertyColumnWidth;
            TupleCtrl.MemberColumn.Width = PropertiesCtrl.ValueColumnWidth;

            PropertiesTab.Header = Localization.Properties;
            TupleTab.Header = Localization.Tuple;

            TabToolBar toolBar = TabCtrl.ToolBar;
            if (toolBar != null)
            {
                RanetToolBarButton copyBtn = new RanetToolBarButton();
                ToolTipService.SetToolTip(copyBtn, Localization.CopyToClipboard_ToolTip);
                copyBtn.Content = UiHelper.CreateIcon(UriResources.Images.Copy16);
                toolBar.Stack.Children.Add(copyBtn);
                copyBtn.Click += new RoutedEventHandler(CopyButton_Click);
            }
        }
        public ValueDeliveryControl()
        {
            Grid LayoutRoot = new Grid();
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition());

            // Грид для свойств ячейки
            Grid Row0_LayoutRoot = new Grid();
            Row0_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            Row0_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            Row0_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Row0_LayoutRoot.RowDefinitions.Add(new RowDefinition());
            
            Border Row0_Border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
            Row0_Border.BorderThickness = new Thickness(1);
            Row0_Border.Padding = new Thickness(5);
            Row0_Border.Child = Row0_LayoutRoot;

            LayoutRoot.Children.Add(Row0_Border);

            TextBlock cellSettings = new TextBlock();
            cellSettings.Margin = new Thickness(0, 0, 0, 0);
            cellSettings.Text = Localization.ValueDeliveryControl_DeliveredCellSettings;
            Row0_LayoutRoot.Children.Add(cellSettings);

            // Тапл ячейки
            m_Tupple = new CellTupleControl();
            m_Tupple.SelectedItemChanged += new EventHandler<TupleItemArgs>(m_Tupple_SelectedItemChanged);
            m_Tupple.Margin = new Thickness(0, 5, 0, 0);
            m_Tupple.Height = 170;
            Row0_LayoutRoot.Children.Add(m_Tupple);
            Grid.SetRow(m_Tupple, 1);

            Grid DeliveryInfo_LayoutRoot = new Grid();
            DeliveryInfo_LayoutRoot.Margin = new Thickness(10, 0, 20, 0);
            DeliveryInfo_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            DeliveryInfo_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto, MinWidth = 50 });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            // Начальное значение
            TextBlock Label_ValueToDelivery = new TextBlock() { Text = Localization.ValueDeliveryDialog_ValueToDelivery, Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(Label_ValueToDelivery);
            m_ValueToDelivery = new TextBlock() { Text = m_OriginalValue.ToString(), Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(m_ValueToDelivery);
            Grid.SetColumn(m_ValueToDelivery, 1);
            
            // Распределено
            TextBlock Label_Delivered = new TextBlock() { Text = Localization.ValueDeliveryDialog_Delivered, Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(Label_Delivered);
            Grid.SetRow(Label_Delivered, 1);
            m_Delivered = new TextBlock() { Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(m_Delivered);
            Grid.SetColumn(m_Delivered, 1);
            Grid.SetRow(m_Delivered, 1);
            
            // Остаток к распределению
            TextBlock Label_RestToDelivery = new TextBlock() { Text = Localization.ValueDeliveryDialog_RestToDelivery, Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(Label_RestToDelivery);
            Grid.SetRow(Label_RestToDelivery, 2);
            m_RestToDelivery = new TextBlock() { Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(m_RestToDelivery);
            Grid.SetColumn(m_RestToDelivery, 1);
            Grid.SetRow(m_RestToDelivery, 2);

            RefreshDeliveredInfo();

            Row0_LayoutRoot.Children.Add(DeliveryInfo_LayoutRoot);
            Grid.SetColumn(DeliveryInfo_LayoutRoot, 1);
            Grid.SetRow(DeliveryInfo_LayoutRoot, 1);

            // Выбор по каким элементам разноска
            Grid DeliveryMode_LayoutRoot = new Grid();
            DeliveryMode_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            DeliveryMode_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto});
            DeliveryMode_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryMode_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryMode_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });

            Border Row1_Border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
            Row1_Border.BorderThickness = new Thickness(1);
            Row1_Border.Margin = new Thickness(0, 5, 0, 5);
            Row1_Border.Padding = new Thickness(5);
            Row1_Border.Child = DeliveryMode_LayoutRoot;

            LayoutRoot.Children.Add(Row1_Border);
            Grid.SetRow(Row1_Border, 1);

            // Заголовок
            TextBlock delivTo = new TextBlock();
            delivTo.Text = Localization.ValueDeliveryControl_DeliveryTo;
            DeliveryMode_LayoutRoot.Children.Add(delivTo);

            // Выбор элементов для разноски (доступен только для режима "выбранные из списка")
            m_MembersChoice = new MemberChoicePopUp();
            m_MembersChoice.IsEnabled = false;
            DeliveryMode_LayoutRoot.Children.Add(m_MembersChoice);
            Grid.SetRow(m_MembersChoice, 2);

            // Тип разноски
            m_DevileryModeCombo = new ComboBoxEx();
            m_DevileryModeCombo.Margin = new Thickness(0, 5, 0, 5);
            ItemControlBase ctrl;
            ctrl = new ItemControlBase(false);
            ctrl.Text = Localization.ValueDeliveryControl_ChildrenMembers;
            m_DevileryModeCombo.Combo.Items.Add(ctrl);
            ctrl = new ItemControlBase(false);
            ctrl.Text = Localization.ValueDeliveryControl_SiblingsMembers;
            m_DevileryModeCombo.Combo.Items.Add(ctrl);
            ctrl = new ItemControlBase(false);
            ctrl.Text = Localization.ValueDeliveryControl_SelectedMembers;
            m_DevileryModeCombo.Combo.Items.Add(ctrl);
            m_DevileryModeCombo.SelectionChanged += new SelectionChangedEventHandler(m_DevileryModeCombo_SelectionChanged);
            m_DevileryModeCombo.Combo.SelectedIndex = 0;
            DeliveryMode_LayoutRoot.Children.Add(m_DevileryModeCombo);
            Grid.SetRow(m_DevileryModeCombo, 1);
            
            // Кнопка Применить
            RanetButton ApplyButton = new RanetButton();
            ApplyButton.Content = Localization.Apply;
            ApplyButton.Margin = new Thickness(5, 5, 0, 5);
            ApplyButton.Click += new RoutedEventHandler(ApplyButton_Click);
            DeliveryMode_LayoutRoot.Children.Add(ApplyButton);
            Grid.SetColumn(ApplyButton, 1);
            Grid.SetRow(ApplyButton, 1);

            // Элементы по которым возможна разноска
            Grid Row2_LayoutRoot = new Grid();
            Row2_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Row2_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            TextBlock membersToDelivery = new TextBlock();
            membersToDelivery.Margin = new Thickness(0, 0, 0, 0);
            membersToDelivery.Text = Localization.ValueDeliveryControl_MembersToDelivery;
            Row2_LayoutRoot.Children.Add(membersToDelivery);

            m_MembersGrid = new RanetDataGrid();
            m_MembersGrid.Margin = new Thickness(0, 5, 0, 0);
            m_MembersGrid.AlternatingRowBackground = new SolidColorBrush(Colors.White);
            m_MembersGrid.RowBackground = new SolidColorBrush(Colors.White);
            m_MembersGrid.AutoGenerateColumns = false;
            m_MembersGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_MembersGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_MembersGrid.RowHeight = 22;

            DataGridTextColumn memberColumn = new DataGridTextColumn();
            memberColumn.Header = Localization.ValueDeliveryControl_Member;
            memberColumn.Binding = new System.Windows.Data.Binding("Caption");
            memberColumn.IsReadOnly = true;
            m_MembersGrid.Columns.Add(memberColumn);

            DataGridTextColumn originalValueColumn = new DataGridTextColumn();
            originalValueColumn.Header = Localization.ValueDeliveryControl_OriginalValue;
            originalValueColumn.Binding = new System.Windows.Data.Binding("OriginalValue");
            originalValueColumn.IsReadOnly = true;
            m_MembersGrid.Columns.Add(originalValueColumn);

            DataGridTextColumn deliveredValueColumn = new DataGridTextColumn();
            deliveredValueColumn.Header = Localization.ValueDeliveryControl_Delivered;
            deliveredValueColumn.Binding = new System.Windows.Data.Binding("DeliveredValue");
            m_MembersGrid.Columns.Add(deliveredValueColumn);

            DataGridTextColumn newValueColumn = new DataGridTextColumn();
            newValueColumn.Header = Localization.ValueDeliveryControl_NewValue;
            newValueColumn.Binding = new System.Windows.Data.Binding("NewValue");
            newValueColumn.IsReadOnly = true;
            m_MembersGrid.Columns.Add(newValueColumn);

            Row2_LayoutRoot.Children.Add(m_MembersGrid);
            Grid.SetRow(m_MembersGrid, 1);

            Border Row2_Border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
            Row2_Border.BorderThickness = new Thickness(1);
            Row2_Border.Padding = new Thickness(5);
            Row2_Border.Child = Row2_LayoutRoot;

            LayoutRoot.Children.Add(Row2_Border);
            Grid.SetRow(Row2_Border, 2);

            this.Content = LayoutRoot;
            m_MembersGrid.CellEditEnded += new EventHandler<DataGridCellEditEndedEventArgs>(m_MembersGrid_CellEditEnded);
        }
        public ValueDeliveryControl()
        {
            Grid LayoutRoot = new Grid();
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition());

            // Грид для свойств ячейки
            Grid Row0_LayoutRoot = new Grid();
            Row0_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            Row0_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            Row0_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Row0_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            Border Row0_Border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
            Row0_Border.BorderThickness = new Thickness(1);
            Row0_Border.Padding = new Thickness(5);
            Row0_Border.Child = Row0_LayoutRoot;

            LayoutRoot.Children.Add(Row0_Border);

            TextBlock cellSettings = new TextBlock();
            cellSettings.Margin = new Thickness(0, 0, 0, 0);
            cellSettings.Text = Localization.ValueDeliveryControl_DeliveredCellSettings;
            Row0_LayoutRoot.Children.Add(cellSettings);

            // Тапл ячейки
            m_Tupple = new CellTupleControl();
            m_Tupple.SelectedItemChanged += new EventHandler<TupleItemArgs>(m_Tupple_SelectedItemChanged);
            m_Tupple.Margin = new Thickness(0, 5, 0, 0);
            m_Tupple.Height = 170;
            Row0_LayoutRoot.Children.Add(m_Tupple);
            Grid.SetRow(m_Tupple, 1);

            Grid DeliveryInfo_LayoutRoot = new Grid();
            DeliveryInfo_LayoutRoot.Margin = new Thickness(10, 0, 20, 0);
            DeliveryInfo_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            DeliveryInfo_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto, MinWidth = 50 });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryInfo_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            // Начальное значение
            TextBlock Label_ValueToDelivery = new TextBlock() { Text = Localization.ValueDeliveryDialog_ValueToDelivery, Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(Label_ValueToDelivery);
            m_ValueToDelivery = new TextBlock() { Text = m_OriginalValue.ToString(), Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(m_ValueToDelivery);
            Grid.SetColumn(m_ValueToDelivery, 1);

            // Распределено
            TextBlock Label_Delivered = new TextBlock() { Text = Localization.ValueDeliveryDialog_Delivered, Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(Label_Delivered);
            Grid.SetRow(Label_Delivered, 1);
            m_Delivered = new TextBlock() { Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(m_Delivered);
            Grid.SetColumn(m_Delivered, 1);
            Grid.SetRow(m_Delivered, 1);

            // Остаток к распределению
            TextBlock Label_RestToDelivery = new TextBlock() { Text = Localization.ValueDeliveryDialog_RestToDelivery, Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(Label_RestToDelivery);
            Grid.SetRow(Label_RestToDelivery, 2);
            m_RestToDelivery = new TextBlock() { Margin = new Thickness(5) };
            DeliveryInfo_LayoutRoot.Children.Add(m_RestToDelivery);
            Grid.SetColumn(m_RestToDelivery, 1);
            Grid.SetRow(m_RestToDelivery, 2);

            RefreshDeliveredInfo();

            Row0_LayoutRoot.Children.Add(DeliveryInfo_LayoutRoot);
            Grid.SetColumn(DeliveryInfo_LayoutRoot, 1);
            Grid.SetRow(DeliveryInfo_LayoutRoot, 1);

            // Выбор по каким элементам разноска
            Grid DeliveryMode_LayoutRoot = new Grid();
            DeliveryMode_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            DeliveryMode_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto});
            DeliveryMode_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryMode_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            DeliveryMode_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });

            Border Row1_Border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
            Row1_Border.BorderThickness = new Thickness(1);
            Row1_Border.Margin = new Thickness(0, 5, 0, 5);
            Row1_Border.Padding = new Thickness(5);
            Row1_Border.Child = DeliveryMode_LayoutRoot;

            LayoutRoot.Children.Add(Row1_Border);
            Grid.SetRow(Row1_Border, 1);

            // Заголовок
            TextBlock delivTo = new TextBlock();
            delivTo.Text = Localization.ValueDeliveryControl_DeliveryTo;
            DeliveryMode_LayoutRoot.Children.Add(delivTo);

            // Выбор элементов для разноски (доступен только для режима "выбранные из списка")
            m_MembersChoice = new MemberChoicePopUp();
            m_MembersChoice.IsEnabled = false;
            DeliveryMode_LayoutRoot.Children.Add(m_MembersChoice);
            Grid.SetRow(m_MembersChoice, 2);

            // Тип разноски
            m_DevileryModeCombo = new ComboBoxEx();
            m_DevileryModeCombo.Margin = new Thickness(0, 5, 0, 5);
            ItemControlBase ctrl;
            ctrl = new ItemControlBase(false);
            ctrl.Text = Localization.ValueDeliveryControl_ChildrenMembers;
            m_DevileryModeCombo.Combo.Items.Add(ctrl);
            ctrl = new ItemControlBase(false);
            ctrl.Text = Localization.ValueDeliveryControl_SiblingsMembers;
            m_DevileryModeCombo.Combo.Items.Add(ctrl);
            ctrl = new ItemControlBase(false);
            ctrl.Text = Localization.ValueDeliveryControl_SelectedMembers;
            m_DevileryModeCombo.Combo.Items.Add(ctrl);
            m_DevileryModeCombo.SelectionChanged += new SelectionChangedEventHandler(m_DevileryModeCombo_SelectionChanged);
            m_DevileryModeCombo.Combo.SelectedIndex = 0;
            DeliveryMode_LayoutRoot.Children.Add(m_DevileryModeCombo);
            Grid.SetRow(m_DevileryModeCombo, 1);

            // Кнопка Применить
            RanetButton ApplyButton = new RanetButton();
            ApplyButton.Content = Localization.Apply;
            ApplyButton.Margin = new Thickness(5, 5, 0, 5);
            ApplyButton.Click += new RoutedEventHandler(ApplyButton_Click);
            DeliveryMode_LayoutRoot.Children.Add(ApplyButton);
            Grid.SetColumn(ApplyButton, 1);
            Grid.SetRow(ApplyButton, 1);

            // Элементы по которым возможна разноска
            Grid Row2_LayoutRoot = new Grid();
            Row2_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Row2_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            TextBlock membersToDelivery = new TextBlock();
            membersToDelivery.Margin = new Thickness(0, 0, 0, 0);
            membersToDelivery.Text = Localization.ValueDeliveryControl_MembersToDelivery;
            Row2_LayoutRoot.Children.Add(membersToDelivery);

            m_MembersGrid = new RanetDataGrid();
            m_MembersGrid.Margin = new Thickness(0, 5, 0, 0);
            m_MembersGrid.AlternatingRowBackground = new SolidColorBrush(Colors.White);
            m_MembersGrid.RowBackground = new SolidColorBrush(Colors.White);
            m_MembersGrid.AutoGenerateColumns = false;
            m_MembersGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_MembersGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_MembersGrid.RowHeight = 22;

            DataGridTextColumn memberColumn = new DataGridTextColumn();
            memberColumn.Header = Localization.ValueDeliveryControl_Member;
            memberColumn.Binding = new System.Windows.Data.Binding("Caption");
            memberColumn.IsReadOnly = true;
            m_MembersGrid.Columns.Add(memberColumn);

            DataGridTextColumn originalValueColumn = new DataGridTextColumn();
            originalValueColumn.Header = Localization.ValueDeliveryControl_OriginalValue;
            originalValueColumn.Binding = new System.Windows.Data.Binding("OriginalValue");
            originalValueColumn.IsReadOnly = true;
            m_MembersGrid.Columns.Add(originalValueColumn);

            DataGridTextColumn deliveredValueColumn = new DataGridTextColumn();
            deliveredValueColumn.Header = Localization.ValueDeliveryControl_Delivered;
            deliveredValueColumn.Binding = new System.Windows.Data.Binding("DeliveredValue");
            m_MembersGrid.Columns.Add(deliveredValueColumn);

            DataGridTextColumn newValueColumn = new DataGridTextColumn();
            newValueColumn.Header = Localization.ValueDeliveryControl_NewValue;
            newValueColumn.Binding = new System.Windows.Data.Binding("NewValue");
            newValueColumn.IsReadOnly = true;
            m_MembersGrid.Columns.Add(newValueColumn);

            Row2_LayoutRoot.Children.Add(m_MembersGrid);
            Grid.SetRow(m_MembersGrid, 1);

            Border Row2_Border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
            Row2_Border.BorderThickness = new Thickness(1);
            Row2_Border.Padding = new Thickness(5);
            Row2_Border.Child = Row2_LayoutRoot;

            LayoutRoot.Children.Add(Row2_Border);
            Grid.SetRow(Row2_Border, 2);

            this.Content = LayoutRoot;
            m_MembersGrid.CellEditEnded += new EventHandler<DataGridCellEditEndedEventArgs>(m_MembersGrid_CellEditEnded);
        }