public KpiViewer()
        {            
            ScrollViewer Scroll = new ScrollViewer();
            Scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            Scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_DataGrid = new DragDropDataGrid();
            m_DataGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            m_DataGrid.VerticalAlignment = VerticalAlignment.Top;
            LayoutRoot = new Grid();
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition());
            m_InputColumn = new ColumnDefinition() { Width = new GridLength(m_InputColumnWidth) };
            LayoutRoot.ColumnDefinitions.Add(m_InputColumn);
            LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { /*Width = new GridLength(2, GridUnitType.Star)*/ });

            // ТУЛБАР 
            m_ToolBar = new RanetToolBar();
            m_ToolBar.Margin = new Thickness(0, 0, 0, 4);
            LayoutRoot.Children.Add(m_ToolBar);
            Grid.SetColumnSpan(m_ToolBar, 2);

            m_ShowMetadataArea = new RanetToggleButton();
            m_ShowMetadataArea.ClickMode = ClickMode.Press;            
            m_ShowMetadataArea.IsChecked = true;
            m_ShowMetadataArea.Checked += new RoutedEventHandler(m_ShowMetadataArea_Checked);
            m_ShowMetadataArea.Unchecked += new RoutedEventHandler(m_ShowMetadataArea_Unchecked);
            m_ShowMetadataArea.Content = UiHelper.CreateIcon(UriResources.Images.Menu16);
            ToolTipService.SetToolTip(m_ShowMetadataArea, Localization.MdxDesigner_ShowQueryDesigner_ToolTip);
            m_ToolBar.AddItem(m_ShowMetadataArea);

            RanetToggleButton showAllButton = new RanetToggleButton();
            showAllButton.ClickMode = ClickMode.Press;
            showAllButton.Content = UiHelper.CreateIcon(UriResources.GetImage("/Ranet.AgOlap;component/Controls/Images/OLAP/KPI/ShowAll.png"));
            showAllButton.Checked += new RoutedEventHandler(showAllButton_Checked);
            showAllButton.Unchecked += new RoutedEventHandler(showAllButton_Unchecked);
            ToolTipService.SetToolTip(showAllButton,Localization.ShowAll_Check);
            showAllButton.Visibility = System.Windows.Visibility.Collapsed;
            m_ToolBar.AddItem(showAllButton);

            RanetToolBarButton m_ApplyChanges = new RanetToolBarButton();
            m_ApplyChanges.ClickMode = ClickMode.Press;
            m_ApplyChanges.Click += new RoutedEventHandler(m_ApplyChanges_Click);
            m_ApplyChanges.Content = UiHelper.CreateIcon(UriResources.Images.Run16);
            ToolTipService.SetToolTip(m_ApplyChanges, Localization.Apply);
            m_ToolBar.AddItem(m_ApplyChanges);

            //showColumnChoice = new RanetToggleButton();
            //showColumnChoice.ClickMode = ClickMode.Press;
            //showColumnChoice.IsChecked = true;
            //showColumnChoice.Checked += new RoutedEventHandler(showColumnChoice_Checked);
            //showColumnChoice.Unchecked += new RoutedEventHandler(showColumnChoice_Unchecked);
            //showColumnChoice.Content = UiHelper.CreateIcon(UriResources.Images.ColumnsArea16);
            //ToolTipService.SetToolTip(showColumnChoice, Localization.MdxDesigner_RunQueryAutomatic);
            //this.m_ToolBar.AddItem(showColumnChoice);  
                     
            Grid Input_LayoutRoot = new Grid();
            Input_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2, GridUnitType.Star) });
            Input_LayoutRoot.Margin = new Thickness(0, 0, 0, 0);
            Input_LayoutRoot.RowDefinitions.Add(new RowDefinition());

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

            Grid Ouput_LayoutRoot = new Grid();
            Ouput_LayoutRoot.Margin = new Thickness(0, 0, 0, 0);
            // По умолчанию высота 0
            var m_MDX_Row = new RowDefinition() { Height = new GridLength(0.0) };
            Ouput_LayoutRoot.RowDefinitions.Add(m_MDX_Row);
            Ouput_LayoutRoot.RowDefinitions.Add(new RowDefinition() /*{ Height = new GridLength(2, GridUnitType.Star) }*/);

            LayoutRoot.Children.Add(Input_Border);
            Grid.SetRow(Input_Border, 1);
            LayoutRoot.Children.Add(Ouput_LayoutRoot);
            Grid.SetRow(Ouput_LayoutRoot, 1);
            Grid.SetColumn(Ouput_LayoutRoot, 1);

            LayoutRoot_VertSplitter = new RanetGridSplitter();
            LayoutRoot_VertSplitter.VerticalAlignment = VerticalAlignment.Stretch;
            LayoutRoot_VertSplitter.HorizontalAlignment = HorizontalAlignment.Right;
            LayoutRoot_VertSplitter.IsTabStop = false;
            LayoutRoot_VertSplitter.Background = new SolidColorBrush(Colors.Transparent);
            LayoutRoot.Children.Add(LayoutRoot_VertSplitter);
            Grid.SetRow(LayoutRoot_VertSplitter, 1);
            Grid.SetColumn(LayoutRoot_VertSplitter, 0);

            // Информация о кубе
            // Просмотрщик куба
            m_ServerExplorer = new ServerExplorerCtrl();
            m_ServerExplorer.Margin = new Thickness(0, 0, 0, 5);   // Для RanetGridSplitter
            m_ServerExplorer.CubeBrowser.DragNodes = true;
            m_ServerExplorer.CubeBrowser.DragStarted += new EventHandler<DragNodeArgs<System.Windows.Controls.Primitives.DragStartedEventArgs>>(CubeBrowser_DragStarted);
            m_ServerExplorer.CubeBrowser.DragDelta += new EventHandler<DragNodeArgs<System.Windows.Controls.Primitives.DragDeltaEventArgs>>(CubeBrowser_DragDelta);
            m_ServerExplorer.CubeBrowser.DragCompleted += new EventHandler<DragNodeArgs<System.Windows.Controls.Primitives.DragCompletedEventArgs>>(CubeBrowser_DragCompleted);
            m_ServerExplorer.CubeSelected += new EventHandler<CustomEventArgs<string>>(m_ServerExplorer_CubeSelected);

            StackPanel rowsPanel = new StackPanel() {Orientation = Orientation.Vertical};
            var cubesComboHeader = new HeaderControl(UriResources.Images.HideEmptyRows16, Localization.ColumnsHeader) { Margin = new Thickness(0, 0, 0, 3) };     
            m_columnsList = new RanetCheckedListBox();
            m_ColumnNames = new Dictionary<string,bool>();
            //m_ColumnNames.Add("Display Folder",false);
            m_ColumnNames.Add("Kpi Name",true);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Kpi Name" , IsChecked = true});
            m_ColumnNames.Add("Kpi Value",true);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Kpi Value", IsChecked = true });
            m_ColumnNames.Add("Kpi Goal", true);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Kpi Goal", IsChecked = true });
            m_ColumnNames.Add("Kpi Variance", true);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Kpi Variance", IsChecked = true });
            m_ColumnNames.Add("Trend", true);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Trend", IsChecked = true });
            m_ColumnNames.Add("Status", true);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Status", IsChecked = true });
            m_ColumnNames.Add("Kpi Weight", false);
            m_columnsList.AddItem(new RanetCheckedItem() { Text = "Kpi Weight", IsChecked = false });
            m_columnsList.ListBox.SelectionChanged += new SelectionChangedEventHandler(m_columnsList_SelectionChanged);
            
            Input_LayoutRoot.Children.Add(m_ServerExplorer);
            Grid.SetRow(m_ServerExplorer, 0);

            rowsPanel.Children.Add(cubesComboHeader);
            rowsPanel.Children.Add(m_columnsList);
            Input_LayoutRoot.Children.Add(rowsPanel);
            Grid.SetRow(rowsPanel, 1);

            // Заголовок
            Table_LayoutRoot = new Grid();
            Table_LayoutRoot.Margin = new Thickness(0, 3, 0, 0);
            Table_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Table_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Table_LayoutRoot.RowDefinitions.Add(new RowDefinition() {Height = GridLength.Auto});
            HeaderControl pivot_Header = new HeaderControl(UriResources.Images.PivotGrid16, Localization.MdxDesigner_QueryResult) { Margin = new Thickness(0, 0, 0, 3) };
            Table_LayoutRoot.Children.Add(pivot_Header);
            Grid.SetRow(Table_LayoutRoot,0);
            m_Waiting = new BusyControl();
            m_Waiting.Text = Localization.Loading;
            Table_LayoutRoot.Children.Add(m_Waiting);
            Grid.SetRow(m_Waiting, 1);

            IsBusy = false;
            //m_OlapDataLoader = GetDataLoader();

            Table_LayoutRoot.Children.Add(m_DataGrid);
            Grid.SetRow(m_DataGrid, 2);
            // Сводная таблица            

            Pivot_Border = new Border() { Padding = new Thickness(3), BorderBrush = new SolidColorBrush(Colors.DarkGray), BorderThickness = new Thickness(1) };
            Pivot_Border.Margin = new Thickness(0, 1, 0, 0);
            Pivot_Border.Child = Table_LayoutRoot;

            Ouput_LayoutRoot.Children.Add(Pivot_Border);
            Grid.SetRow(Pivot_Border, 1);

            //var Output_HorzSplitter = new RanetGridSplitter();
            //Output_HorzSplitter.VerticalAlignment = VerticalAlignment.Bottom;
            //Output_HorzSplitter.HorizontalAlignment = HorizontalAlignment.Stretch;
            //Output_HorzSplitter.IsTabStop = false;
            //Output_HorzSplitter.Background = new SolidColorBrush(Colors.Transparent);
            //Ouput_LayoutRoot.Children.Add(Output_HorzSplitter);
            //Grid.SetRow(Output_HorzSplitter, 0);
            //Grid.SetColumn(Output_HorzSplitter, 0);            
            //

            this.Content = LayoutRoot;            
        }
		public UpdateablePivotGridControl()
		{
			RowDefinition row0 = new RowDefinition();
			row0.Height = GridLength.Auto;
			RowDefinition row1 = new RowDefinition();

			LayoutRoot.RowDefinitions.Add(row0);
			LayoutRoot.RowDefinitions.Add(row1);

			RefreshButton = new RanetToolBarButton();
			RefreshButton.Click += new RoutedEventHandler(RefreshButton_Click);
			RefreshButton.Content = UiHelper.CreateIcon(UriResources.Images.Refresh16);
			ToolTipService.SetToolTip(RefreshButton, Localization.PivotGrid_RefreshButton_ToolTip);

			ToBeginButton = new RanetToolBarButton();
			ToBeginButton.Click += new RoutedEventHandler(ToBeginButton_Click);
			ToBeginButton.Content = UiHelper.CreateIcon(UriResources.Images.ToBegin16);
			ToolTipService.SetToolTip(ToBeginButton, Localization.PivotGrid_ToBeginButton_ToolTip);

			BackButton = new RanetToolBarButton();
			BackButton.Click += new RoutedEventHandler(BackButton_Click);
			BackButton.Content = UiHelper.CreateIcon(UriResources.Images.Back16);
			ToolTipService.SetToolTip(BackButton, Localization.PivotGrid_BackButton_ToolTip);

			ForwardButton = new RanetToolBarButton();
			ForwardButton.Click += new RoutedEventHandler(ForwardButton_Click);
			ForwardButton.Content = UiHelper.CreateIcon(UriResources.Images.Forward16);
			ToolTipService.SetToolTip(ForwardButton, Localization.PivotGrid_ForwardButton_ToolTip);

			ToEndButton = new RanetToolBarButton();
			ToEndButton.Click += new RoutedEventHandler(ToEndButton_Click);
			ToEndButton.Content = UiHelper.CreateIcon(UriResources.Images.ToEnd16);
			ToolTipService.SetToolTip(ToEndButton, Localization.PivotGrid_ToEndButton_ToolTip);

			EditButton = new RanetToggleButton();
			ToolTipService.SetToolTip(EditButton, Localization.PivotGrid_EditButton_ToolTip);
			EditButton.Checked += new RoutedEventHandler(EditButton_Click);
			EditButton.Unchecked += new RoutedEventHandler(EditButton_Click);
			EditButton.Content = UiHelper.CreateIcon(UriResources.Images.EditCells16);

			UseChangesCasheButton = new RanetToggleButton();
			ToolTipService.SetToolTip(UseChangesCasheButton, Localization.PivotGrid_UseChangesCasheButton_ToolTip);
			UseChangesCasheButton.Checked += new RoutedEventHandler(UseChangesCasheButton_Checked);
			UseChangesCasheButton.Unchecked += new RoutedEventHandler(UseChangesCasheButton_Checked);
			UseChangesCasheButton.Content = UiHelper.CreateIcon(UriResources.Images.UseChangesCache16);

			CopyToClipboardButton = new RanetToolBarButton();
			ToolTipService.SetToolTip(CopyToClipboardButton, Localization.PivotGrid_CopyToClipboardButton_ToolTip);
			CopyToClipboardButton.Click += new RoutedEventHandler(CopyToClipboardoButton_Click);
			CopyToClipboardButton.Content = UiHelper.CreateIcon(UriResources.Images.Copy16);

			PasteFromClipboardButton = new RanetToolBarButton();
			ToolTipService.SetToolTip(PasteFromClipboardButton, Localization.PivotGrid_PasteFromClipboardButton_ToolTip);
			PasteFromClipboardButton.Click += new RoutedEventHandler(PasteFromClipboardoButton_Click);
			PasteFromClipboardButton.Content = UiHelper.CreateIcon(UriResources.Images.Paste16);

			ConfirmEditButton = new RanetToolBarButton(UriResources.Images.ConfirmEdit16, Localization.PivotGrid_ConfirmEditButton_Caption);
			ToolTipService.SetToolTip(ConfirmEditButton, Localization.PivotGrid_ConfirmEditButton_ToolTip);
			ConfirmEditButton.Click += new RoutedEventHandler(ConfirmEditButton_Click);

			CancelEditButton = new RanetToolBarButton();
			ToolTipService.SetToolTip(CancelEditButton, Localization.PivotGrid_CancelEditButton_ToolTip);
			CancelEditButton.Click += new RoutedEventHandler(CancelEditButton_Click);
			CancelEditButton.Content = UiHelper.CreateIcon(UriResources.Images.CancelEdit16);

			RestoreDefaultSizeButton = new RanetToolBarButton();
			ToolTipService.SetToolTip(RestoreDefaultSizeButton, Localization.PivotGrid_RestoreDefaultSize_ToolTip);
			RestoreDefaultSizeButton.Click += new RoutedEventHandler(RestoreDefaultSizeButton_Click);
			RestoreDefaultSizeButton.Content = UiHelper.CreateIcon(UriResources.Images.RestoreSize16);

			HideEmptyRowsButton = new RanetToggleButton();
			HideEmptyRowsButton.Click += new RoutedEventHandler(HideEmptyRowsButton_Click);
			HideEmptyRowsButton.Content = UiHelper.CreateIcon(UriResources.Images.HideEmptyRows16);
			ToolTipService.SetToolTip(HideEmptyRowsButton, Localization.PivotGrid_HideEmptyRowsButton_ToolTip);

			HideEmptyColumnsButton = new RanetToggleButton();
			HideEmptyColumnsButton.ClickMode = ClickMode.Press;
			HideEmptyColumnsButton.Click += new RoutedEventHandler(HideEmptyColumnsButton_Click);
			HideEmptyColumnsButton.Content = UiHelper.CreateIcon(UriResources.Images.HideEmptyColumns16);
			ToolTipService.SetToolTip(HideEmptyColumnsButton, Localization.PivotGrid_HideEmptyColumnsButton_ToolTip);

			GoToFocusedCellButton = new RanetToolBarButton();
			GoToFocusedCellButton.Click += new RoutedEventHandler(GoToFocusedCellButton_Click);
			GoToFocusedCellButton.Content = UiHelper.CreateIcon(UriResources.Images.ToFocused16);
			ToolTipService.SetToolTip(GoToFocusedCellButton, Localization.PivotGrid_GoToFocusedCellButton_ToolTip);

			ExportToExcelButton = new RanetToolBarButton();
			ToolTipService.SetToolTip(ExportToExcelButton, Localization.PivotGrid_ExportToExcelButton_ToolTip);
			ExportToExcelButton.Click += new RoutedEventHandler(ExportToExcelButton_Click);
			ExportToExcelButton.Content = UiHelper.CreateIcon(UriResources.Images.ExportToExcel16);

			RotateAxesButton = new RanetToggleButton();
			RotateAxesButton.ClickMode = ClickMode.Press;
			RotateAxesButton.Click += new RoutedEventHandler(RotateAxesButton_Click);
			RotateAxesButton.Content = UiHelper.CreateIcon(UriResources.Images.RotateAxes16);
			ToolTipService.SetToolTip(RotateAxesButton, Localization.PivotGrid_RotateAxesButton_ToolTip);

			HideHintsButton = new RanetToggleButton();
			HideHintsButton.ClickMode = ClickMode.Press;
			HideHintsButton.Click += new RoutedEventHandler(HideHintsButton_Click);
			HideHintsButton.Content = UiHelper.CreateIcon(UriResources.Images.HideHint16);
			ToolTipService.SetToolTip(HideHintsButton, Localization.PivotGrid_HideHintsButton_ToolTip);

			ConditionsDesignerButton = new RanetToggleButton();
			ConditionsDesignerButton.ClickMode = ClickMode.Press;
			ConditionsDesignerButton.Click += new RoutedEventHandler(ConditionsDesignerButton_Click);
			ConditionsDesignerButton.Content = UiHelper.CreateIcon(UriResources.Images.CellConditionsDesigner16);
			ConditionsDesignerButton.Visibility = Visibility.Collapsed;
			ToolTipService.SetToolTip(ConditionsDesignerButton, Localization.PivotGrid_CellsConditionsDesignerButton_ToolTip);

			ZoomControl = new ZoomingToolBarControl();
			ToolTipService.SetToolTip(ZoomControl, Localization.PivotGrid_ZoomingControl_ToolTip);
			ZoomControl.ValueChanged += new EventHandler(ZoomControl_ValueChanged);

			ToolBar.AddItem(RefreshButton);
			ToolBar.AddItem(m_NavigationButtons_Splitter);
			ToolBar.AddItem(ToBeginButton);
			ToolBar.AddItem(BackButton);
			ToolBar.AddItem(ForwardButton);
			ToolBar.AddItem(ToEndButton);
			NavigationToolBarSplitter = new RanetToolBarSplitter();
			ToolBar.AddItem(NavigationToolBarSplitter);
			ToolBar.AddItem(EditButton);
			ToolBar.AddItem(CopyToClipboardButton);
			ToolBar.AddItem(PasteFromClipboardButton);
			ToolBar.AddItem(UseChangesCasheButton);
			ToolBar.AddItem(ConfirmEditButton);
			ToolBar.AddItem(CancelEditButton);
			ToolBar.AddItem(new RanetToolBarSplitter());
			ToolBar.AddItem(RestoreDefaultSizeButton);
			ToolBar.AddItem(HideEmptyRowsButton);
			ToolBar.AddItem(HideEmptyColumnsButton);
			ToolBar.AddItem(GoToFocusedCellButton);
			ToolBar.AddItem(RotateAxesButton);
			ToolBar.AddItem(HideHintsButton);
			ToolBar.AddItem(ConditionsDesignerButton);
			ToolBar.AddItem(new RanetToolBarSplitter());
			ToolBar.AddItem(ExportToExcelButton);
			ToolBar.AddItem(ZoomControl);

			LayoutRoot.Children.Add(ToolBar);
			ToolBar.Margin = new Thickness(0, 0, 0, 3);

			// Сводная таблица
			//m_PivotGridPanel = new PivotGridPanel();
			//LayoutRoot.Children.Add(m_PivotGridPanel);
			//Grid.SetRow(m_PivotGridPanel, 1);

			m_PivotGrid = GetPivotGridControl();
			LayoutRoot.Children.Add(m_PivotGrid);
			Grid.SetRow(m_PivotGrid, 1);

			PivotGrid.ExecuteMemberAction += new MemberActionEventHandler(PivotGrid_ExecuteMemberAction);
			PivotGrid.CellValueChanged += new CellValueChangedEventHandler(CellsControl_CellValueChanged);
			PivotGrid.UndoCellChanges += new EventHandler(CellsControl_UndoCellChanges);
			PivotGrid.Cells_ContextMenuCreated += new EventHandler(CellsControl_ContextMenuCreated);
			PivotGrid.Columns_ContextMenuCreated += new EventHandler(ColumnsControl_ContextMenuCreated);
			PivotGrid.Rows_ContextMenuCreated += new EventHandler(RowsControl_ContextMenuCreated);
			PivotGrid.InitializeContextMenu += new EventHandler<CustomContextMenuEventArgs>(PivotGrid_InitializeContextMenu);

			UpdateToolbarButtons(null);
			UpdateEditToolBarButtons();

			grdIsWaiting = new Grid() { Background = new SolidColorBrush(Color.FromArgb(125, 0xFF, 0xFF, 0xFF)) };
			grdIsWaiting.Visibility = Visibility.Collapsed;
			BusyControl m_Waiting = new BusyControl();
			m_Waiting.Text = Localization.Loading;
			grdIsWaiting.Children.Add(m_Waiting);

			LayoutRoot.Children.Add(grdIsWaiting);
			Grid.SetColumnSpan(grdIsWaiting, LayoutRoot.ColumnDefinitions.Count > 0 ? LayoutRoot.ColumnDefinitions.Count : 1);
			Grid.SetRowSpan(grdIsWaiting, LayoutRoot.RowDefinitions.Count > 0 ? LayoutRoot.RowDefinitions.Count : 1);
			this.Content = LayoutRoot;

			PivotGrid.Cells_PerformControlAction += new EventHandler<ControlActionEventArgs<CellInfo>>(CellsControl_PerformControlAction);
			PivotGrid.Members_PerformControlAction += new EventHandler<ControlActionEventArgs<MemberControl>>(MembersArea_PerformControlAction);

			m_OlapDataLoader = GetOlapDataLoader();
			m_OlapDataLoader.DataLoaded += new EventHandler<DataLoaderEventArgs>(OlapDataLoader_DataLoaded);

			m_StorageManager = GetStorageManager();
			m_StorageManager.InvokeCompleted += new EventHandler<DataLoaderEventArgs>(StorageManager_ActionCompleted);

			// Метод Initialize необходимо вызывать для RotVisual элемента
			// всего приложения. Перенес его в ClientApp.
			//ScrollViewerMouseWheelSupport.Initialize(this);
			//m_ScrollableDataControl.ScrollView.AddMouseWheelSupport();

			this.KeyDown += new KeyEventHandler(UpdateablePivotGridControl_KeyDown);

			OlapTransactionManager.AfterCommandComplete += new EventHandler<TransactionCommandResultEventArgs>(AnalysisTransactionManager_AfterCommandComplete);
		}
        public PivotMdxDesignerControl()
        {
            ScrollViewer Scroll = new ScrollViewer();
            Scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            Scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

            LayoutRoot = new Grid();
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition());
            m_Input_Column = new ColumnDefinition() { Width = new GridLength(m_InputColumnWidth) };
            LayoutRoot.ColumnDefinitions.Add(m_Input_Column);
            LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { /*Width = new GridLength(2, GridUnitType.Star)*/ });

            // ТУЛБАР 
            m_ToolBar = new RanetToolBar();
            m_ToolBar.Margin = new Thickness(0, 0, 0, 4);
            LayoutRoot.Children.Add(m_ToolBar);
            Grid.SetColumnSpan(m_ToolBar, 2);

            m_ShowMetadataArea = new RanetToggleButton();
            m_ShowMetadataArea.ClickMode = ClickMode.Press;
            m_ShowMetadataArea.Click += new RoutedEventHandler(m_ShowMetadataArea_Click);
            m_ShowMetadataArea.IsChecked = new bool?(true);
            m_ShowMetadataArea.Content = UiHelper.CreateIcon(UriResources.Images.Menu16);
            ToolTipService.SetToolTip(m_ShowMetadataArea, Localization.MdxDesigner_ShowQueryDesigner_ToolTip);
            m_ToolBar.AddItem(m_ShowMetadataArea);

            m_ShowMDXQuery = new RanetToggleButton();
            m_ShowMDXQuery.ClickMode = ClickMode.Press;
            m_ShowMDXQuery.Click += new RoutedEventHandler(m_ShowMDXQuery_Click);
            m_ShowMDXQuery.IsChecked = new bool?(false);
            m_ShowMDXQuery.Content = UiHelper.CreateIcon(UriResources.Images.Mdx16);
            ToolTipService.SetToolTip(m_ShowMDXQuery, Localization.MdxDesigner_ShowQuery_ToolTip);
            m_ToolBar.AddItem(m_ShowMDXQuery);

            m_EditMDXQuery = new RanetToggleButton();
            m_EditMDXQuery.ClickMode = ClickMode.Press;
            m_EditMDXQuery.Click += new RoutedEventHandler(m_EditMDXQuery_Click);
            m_EditMDXQuery.IsChecked = new bool?(false);
            m_EditMDXQuery.Content = UiHelper.CreateIcon(UriResources.Images.Edit16);
            ToolTipService.SetToolTip(m_EditMDXQuery, Localization.MdxDesigner_EditQuery_ToolTip);
            m_ToolBar.AddItem(m_EditMDXQuery);

            m_RunAreaSplitter = new RanetToolBarSplitter();
            m_ToolBar.AddItem(m_RunAreaSplitter);

            m_CalculatedMemberEditor = new RanetToolBarButton();
            m_CalculatedMemberEditor.Content = UiHelper.CreateIcon(UriResources.Images.CustomCalculations16);
            m_CalculatedMemberEditor.Click += new RoutedEventHandler(m_CalculatedMemberEditor_Click);
            ToolTipService.SetToolTip(m_CalculatedMemberEditor, Localization.MdxDesigner_CalculatedMemberEditor);
            m_ToolBar.AddItem(m_CalculatedMemberEditor);

            m_RunQueryAutomatic = new RanetToggleButton();
            m_RunQueryAutomatic.ClickMode = ClickMode.Press;
            m_RunQueryAutomatic.IsChecked = new bool?(true);
            m_RunQueryAutomatic.Content = UiHelper.CreateIcon(UriResources.Images.AutoRun16);
            ToolTipService.SetToolTip(m_RunQueryAutomatic, Localization.MdxDesigner_RunQueryAutomatic);
            m_ToolBar.AddItem(m_RunQueryAutomatic);

            m_ExecuteQuery = new RanetToolBarButton();
            m_ExecuteQuery.Content = UiHelper.CreateIcon(UriResources.Images.Run16);
            m_ExecuteQuery.Click += new RoutedEventHandler(m_ExecuteQuery_Click);
            ToolTipService.SetToolTip(m_ExecuteQuery, Localization.MdxDesigner_ExecuteQuery);
            m_ToolBar.AddItem(m_ExecuteQuery);

            m_StorageAreaSplitter = new RanetToolBarSplitter();
            m_ToolBar.AddItem(m_StorageAreaSplitter);

            m_ImportLayout = new RanetToolBarButton();
            m_ImportLayout.Content = UiHelper.CreateIcon(UriResources.Images.FileImport16);
            m_ImportLayout.Click += new RoutedEventHandler(m_ImportLayout_Click);
            ToolTipService.SetToolTip(m_ImportLayout, Localization.MdxDesigner_ImportLayout_ToolTip);
            m_ToolBar.AddItem(m_ImportLayout);

            m_ExportLayout = new RanetToolBarButton();
            m_ExportLayout.Content = UiHelper.CreateIcon(UriResources.Images.FileExport16);
            m_ExportLayout.Click += new RoutedEventHandler(m_ExportLayout_Click);
            ToolTipService.SetToolTip(m_ExportLayout, Localization.MdxDesigner_ExportLayout_ToolTip);
            m_ToolBar.AddItem(m_ExportLayout);

            Grid Input_LayoutRoot = new Grid();
            Input_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2, GridUnitType.Star) });
            Input_LayoutRoot.Margin = new Thickness(0, 0, 0, 0);
            Input_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            Input_Border = new Border() { Padding = new Thickness(3), BorderBrush = new SolidColorBrush(Colors.DarkGray), BorderThickness = new Thickness(1) };
            Input_Border.Margin = new Thickness(0, 0, 3, 0);
            Input_Border.Child = Input_LayoutRoot;

            Grid Ouput_LayoutRoot = new Grid();
            Ouput_LayoutRoot.Margin = new Thickness(0, 0, 0, 0);
            // По умолчанию высота 0
            m_MDX_Row = new RowDefinition(){ Height = new GridLength(0.0)};
            Ouput_LayoutRoot.RowDefinitions.Add(m_MDX_Row);
            Ouput_LayoutRoot.RowDefinitions.Add(new RowDefinition() /*{ Height = new GridLength(2, GridUnitType.Star) }*/);

            LayoutRoot.Children.Add(Input_Border);
            Grid.SetRow(Input_Border, 1);
            LayoutRoot.Children.Add(Ouput_LayoutRoot);
            Grid.SetRow(Ouput_LayoutRoot, 1);
            Grid.SetColumn(Ouput_LayoutRoot, 1);

            LayoutRoot_VertSplitter = new GridSplitter();
            LayoutRoot_VertSplitter.VerticalAlignment = VerticalAlignment.Stretch;
            LayoutRoot_VertSplitter.HorizontalAlignment = HorizontalAlignment.Right;
            LayoutRoot_VertSplitter.Width = 3;
            LayoutRoot_VertSplitter.IsTabStop = false;
            LayoutRoot_VertSplitter.Background = new SolidColorBrush(Colors.Transparent);
            LayoutRoot.Children.Add(LayoutRoot_VertSplitter);
            Grid.SetRow(LayoutRoot_VertSplitter, 1);
            Grid.SetColumn(LayoutRoot_VertSplitter, 0);

            // Информация о кубе
            Grid Cube_LayotRoot = new Grid();
            Cube_LayotRoot.Margin = new Thickness(0, 3, 0, 0);
            Cube_LayotRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Cube_LayotRoot.RowDefinitions.Add(new RowDefinition());
            
            // Заголовок
            //HeaderControl cube_Header = new HeaderControl(UriResources.Images.Cube16, Localization.MdxDesigner_CubeMetadata) { Margin = new Thickness(0, 0, 0, 3) };
            //Cube_LayotRoot.Children.Add(cube_Header);

            // Просмотрщик куба
            m_ServerExplorer = new ServerExplorerCtrl();
            m_ServerExplorer.CubeBrowser.DragNodes = true;
            m_ServerExplorer.CubeBrowser.DragStarted += new EventHandler<DragNodeArgs<DragStartedEventArgs>>(m_CubeBrowser_DragStarted);
            m_ServerExplorer.CubeBrowser.DragDelta += new EventHandler<DragNodeArgs<DragDeltaEventArgs>>(m_CubeBrowser_DragDelta);
            m_ServerExplorer.CubeBrowser.DragCompleted += new EventHandler<DragNodeArgs<DragCompletedEventArgs>>(m_CubeBrowser_DragCompleted);
            m_ServerExplorer.CubeSelected += new EventHandler<CustomEventArgs<string>>(m_ServerExplorer_CubeSelected);
            Cube_LayotRoot.Children.Add(m_ServerExplorer);
            Grid.SetRow(m_ServerExplorer, 1);

            Input_LayoutRoot.Children.Add(Cube_LayotRoot);
            Grid.SetRow(Cube_LayotRoot, 0);

            Areas_LayoutRoot = new Grid();
            Areas_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            Areas_LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
            Areas_LayoutRoot.RowDefinitions.Add(new RowDefinition());
            Areas_LayoutRoot.RowDefinitions.Add(new RowDefinition());

            m_FilterAreaContainer = new PivotAreaContainer();
            m_FilterAreaContainer.ItemRemoved += new EventHandler<AreaItemArgs>(AreaContainer_ItemRemoved);
            m_FilterAreaContainer.Margin = new Thickness(0, 5, 0, 0);
            m_FilterAreaContainer.Icon = UriResources.Images.FiltersArea16;
            m_FilterAreaContainer.Caption = Localization.MdxDesigner_FilterArea_Caption;
            m_FilterAreaContainer.BeforeShowContextMenu += new EventHandler<AreaItemArgs>(m_FilterAreaContainer_BeforeShowContextMenu);
            m_FilterAreaContainer.ItemsListChanged += new EventHandler(AreaContainer_ItemsListChanged);
            Areas_LayoutRoot.Children.Add(m_FilterAreaContainer);
            Grid.SetRow(m_FilterAreaContainer, 0);
            Grid.SetColumn(m_FilterAreaContainer, 0);

            m_RowsAreaContainer = new PivotAreaContainer();
            m_RowsAreaContainer.ItemRemoved += new EventHandler<AreaItemArgs>(AreaContainer_ItemRemoved);
            m_RowsAreaContainer.Margin = new Thickness(0, 5, 0, 0);
            m_RowsAreaContainer.Icon = UriResources.Images.RowsArea16;
            m_RowsAreaContainer.Caption = Localization.MdxDesigner_RowsArea_Caption;
            m_RowsAreaContainer.BeforeShowContextMenu += new EventHandler<AreaItemArgs>(m_RowsAreaContainer_BeforeShowContextMenu);
            m_RowsAreaContainer.ItemsListChanged += new EventHandler(AreaContainer_ItemsListChanged);
            Areas_LayoutRoot.Children.Add(m_RowsAreaContainer);
            Grid.SetRow(m_RowsAreaContainer, 1);
            Grid.SetColumn(m_RowsAreaContainer, 0);

            m_ColumnsAreaContainer = new PivotAreaContainer();
            m_ColumnsAreaContainer.ItemRemoved += new EventHandler<AreaItemArgs>(AreaContainer_ItemRemoved);
            m_ColumnsAreaContainer.Margin = new Thickness(5, 5, 0, 0);
            m_ColumnsAreaContainer.Icon = UriResources.Images.ColumnsArea16;
            m_ColumnsAreaContainer.Caption = Localization.MdxDesigner_ColumnsArea_Caption;
            m_ColumnsAreaContainer.BeforeShowContextMenu += new EventHandler<AreaItemArgs>(m_ColumnsAreaContainer_BeforeShowContextMenu);
            m_ColumnsAreaContainer.ItemsListChanged += new EventHandler(AreaContainer_ItemsListChanged);
            Areas_LayoutRoot.Children.Add(m_ColumnsAreaContainer);
            Grid.SetRow(m_ColumnsAreaContainer, 0);
            Grid.SetColumn(m_ColumnsAreaContainer, 1);

            m_DataAreaContainer = new PivotAreaContainer();
            m_DataAreaContainer.ItemRemoved += new EventHandler<AreaItemArgs>(AreaContainer_ItemRemoved);
            m_DataAreaContainer.Margin = new Thickness(5, 5, 0, 0);
            m_DataAreaContainer.Icon = UriResources.Images.DataArea16;
            m_DataAreaContainer.Caption = Localization.MdxDesigner_DataArea_Caption;
            m_DataAreaContainer.ItemsListChanged += new EventHandler(AreaContainer_ItemsListChanged);
            Areas_LayoutRoot.Children.Add(m_DataAreaContainer);
            Grid.SetRow(m_DataAreaContainer, 1);
            Grid.SetColumn(m_DataAreaContainer, 1);

            Input_LayoutRoot.Children.Add(Areas_LayoutRoot);
            Grid.SetRow(Areas_LayoutRoot, 1);

            GridSplitter Input_HorzSplitter = new GridSplitter();
            Input_HorzSplitter.VerticalAlignment = VerticalAlignment.Bottom;
            Input_HorzSplitter.HorizontalAlignment = HorizontalAlignment.Stretch;
            Input_HorzSplitter.Height = 3;
            Input_HorzSplitter.IsTabStop = false;
            Input_HorzSplitter.Background = new SolidColorBrush(Colors.Transparent);
            Input_LayoutRoot.Children.Add(Input_HorzSplitter);
            Grid.SetRow(Input_HorzSplitter, 0);
            Grid.SetColumn(Input_HorzSplitter, 0);

            // Результат выполнения запроса
            Grid Pivot_LayotRoot = new Grid();
            Pivot_LayotRoot.Margin = new Thickness(0, 3, 0, 0);
            Pivot_LayotRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Pivot_LayotRoot.RowDefinitions.Add(new RowDefinition());

            // Заголовок
            HeaderControl pivot_Header = new HeaderControl(UriResources.Images.PivotGrid16, Localization.MdxDesigner_QueryResult) { Margin = new Thickness(0, 0, 0, 3) };
            Pivot_LayotRoot.Children.Add(pivot_Header);

            // Сводная таблица
            m_PivotGrid = new UpdateablePivotGridControl();
            m_PivotGrid.Margin = new Thickness(0, 0, 0, 0);
            m_PivotGrid.IsUpdateable = true;
            m_PivotGrid.ColumnsIsInteractive = true;
            m_PivotGrid.RowsIsInteractive = true;
            m_PivotGrid.ShowToolBar = true;
            Pivot_LayotRoot.Children.Add(m_PivotGrid);
            Grid.SetRow(m_PivotGrid, 1);

            Border Pivot_Border = new Border() { Padding = new Thickness(3), BorderBrush = new SolidColorBrush(Colors.DarkGray), BorderThickness = new Thickness(1) };
            Pivot_Border.Margin = new Thickness(0, 0, 0, 0);
            Pivot_Border.Child = Pivot_LayotRoot;

            Ouput_LayoutRoot.Children.Add(Pivot_Border);
            Grid.SetRow(Pivot_Border, 1);

            Output_HorzSplitter = new GridSplitter();
            Output_HorzSplitter.VerticalAlignment = VerticalAlignment.Bottom;
            Output_HorzSplitter.HorizontalAlignment = HorizontalAlignment.Stretch;
            Output_HorzSplitter.Height = 3;
            Output_HorzSplitter.IsTabStop = false;
            Output_HorzSplitter.Background = new SolidColorBrush(Colors.Transparent);
            Ouput_LayoutRoot.Children.Add(Output_HorzSplitter);
            Grid.SetRow(Output_HorzSplitter, 0);
            Grid.SetColumn(Output_HorzSplitter, 0);

            // Информация о MDX запросе
            Grid Mdx_LayotRoot = new Grid();
            Mdx_LayotRoot.Margin = new Thickness(0, 3, 0, 0);
            Mdx_LayotRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Mdx_LayotRoot.RowDefinitions.Add(new RowDefinition());

            // Заголовок
            HeaderControl mdx_Header = new HeaderControl(UriResources.Images.Mdx16, Localization.MdxDesigner_MdxQuery) { Margin = new Thickness(0, 0, 0, 3) };
            Mdx_LayotRoot.Children.Add(mdx_Header);
            
            // Текст запроса
            m_MdxQuery = new RichTextBox();
            m_MdxQuery.AcceptsReturn = true;
            m_MdxQuery.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_MdxQuery.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            m_MdxQuery.IsReadOnly = true;
            Mdx_LayotRoot.Children.Add(m_MdxQuery);
            Grid.SetRow(m_MdxQuery, 1);

            Mdx_Border = new Border() { Padding = new Thickness(3), BorderBrush = new SolidColorBrush(Colors.DarkGray), BorderThickness = new Thickness(1) };
            Mdx_Border.Margin = new Thickness(0, 0, 0, 4);
            Mdx_Border.Child = Mdx_LayotRoot;

            Ouput_LayoutRoot.Children.Add(Mdx_Border);
            Grid.SetRow(Mdx_Border, 0);

            AllowDragDrop(m_FilterAreaContainer);
            AllowDragDrop(m_ColumnsAreaContainer);
            AllowDragDrop(m_RowsAreaContainer);
            AllowDragDrop(m_DataAreaContainer);

            //Scroll.Content = LayoutRoot;

            m_ServerExplorer.OlapDataLoader = GetOlapDataLoader();
            m_PivotGrid.OlapDataLoader = GetOlapDataLoader();
            m_StorageManager = GetStorageManager();
            m_StorageManager.InvokeCompleted += new EventHandler<DataLoaderEventArgs>(StorageManager_ActionCompleted);

            this.Content = LayoutRoot;
        }
        public MemberChoiceControl()
        {
            try
            {
                m_Initializing = true;
                Grid LayoutRoot = new Grid();
                LayoutRoot.RowDefinitions.Add(new RowDefinition());
                // Строка для кнопок
                //OK LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Star), MinWidth = 50 });
                // Колонка для свойств
                LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { MinWidth = 50 });

                tabControl = new RanetTabControl();
                tabControl.TabCtrl.SelectionChanged += new SelectionChangedEventHandler(TabControl_SelectionChanged);

                membersTab = new TabItem();
                membersTab.Header = Localization.Members;
                membersTab.Style = tabControl.Resources["TabControlOutputItem"] as Style;

                findTab = new TabItem();
                findTab.Header = Localization.Find;
                findTab.Style = tabControl.Resources["TabControlOutputItem"] as Style;

                mdxSetTab = new TabItem();
                mdxSetTab.Header = Localization.MemberChoice_Selected;
                mdxSetTab.Style = tabControl.Resources["TabControlOutputItem"] as Style;

                tabControl.TabCtrl.Items.Add(membersTab);
                tabControl.TabCtrl.Items.Add(findTab);
                tabControl.TabCtrl.Items.Add(mdxSetTab);

                LayoutRoot.Children.Add(tabControl);

                //OK StackPanel buttonsPanel = new StackPanel() { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right };
                //LayoutRoot.Children.Add(buttonsPanel);
                //Grid.SetRow(buttonsPanel, 1);

                //Border border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray), BorderThickness = new Thickness(1), Padding = new Thickness(5), Background = new SolidColorBrush(Colors.White) };
                //border.Child = LayoutRoot;

                // Растягиваем дерево
                Grid.SetColumnSpan(tabControl, 2);

                // Закладка MEMBERS
                Grid membersTab_LayoutRoot = new Grid();
                membersTab.Content = membersTab_LayoutRoot;
                membersTab_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                membersTab_LayoutRoot.RowDefinitions.Add(new RowDefinition());

                membersTree = new CustomTree() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
                membersTree.Margin = new Thickness(0, 3, 0, 0);
                membersTree.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(membersTree_SelectedItemChanged);
                membersTab_LayoutRoot.Children.Add(membersTree);
                Grid.SetRow(membersTree, 1);

                GridSplitter splitter_Vert = new GridSplitter();
                splitter_Vert.IsTabStop = false;
                LayoutRoot.Children.Add(splitter_Vert);
                Grid.SetColumn(splitter_Vert, 0);
                Grid.SetRow(splitter_Vert, 0);
                splitter_Vert.Background = new SolidColorBrush(Colors.Transparent);
                splitter_Vert.HorizontalAlignment = HorizontalAlignment.Right;
                splitter_Vert.VerticalAlignment = VerticalAlignment.Stretch;
                splitter_Vert.Width = 3;

                // Свойства элемента
                m_CurrentMemberControl = new PropertiesControl();
                m_CurrentMemberControl.Background = new SolidColorBrush(Color.FromArgb(0x7F, 128, 128, 128));
                m_CurrentMemberControl.PropertiesList.PropertyColumnWidth = new DataGridLength(100);
                m_PropertiesLayoutBorder = new Border() { BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0x80, 0x80)), BorderThickness = new Thickness(1) };
                m_PropertiesLayoutBorder.Child = m_CurrentMemberControl;
                LayoutRoot.Children.Add(m_PropertiesLayoutBorder);
                Grid.SetRow(m_PropertiesLayoutBorder, 0);
                Grid.SetColumn(m_PropertiesLayoutBorder, 1);

                // Прячем свойства
                m_PropertiesLayoutBorder.Visibility = Visibility.Collapsed;

                StackPanel members_toolBar = new StackPanel();
                members_toolBar.Orientation = Orientation.Horizontal;

                membersTab_LayoutRoot.Children.Add(members_toolBar);
                Grid.SetRow(members_toolBar, 0);
                Grid.SetColumnSpan(members_toolBar, 2);

                RanetToolBarButton Refresh_Button = new RanetToolBarButton();
                Refresh_Button.Margin = new Thickness(0, 0, 0, 0);
                Refresh_Button.Click += new RoutedEventHandler(RefreshButton_Click);
                Refresh_Button.Content = UiHelper.CreateIcon(UriResources.Images.Refresh16);
                ToolTipService.SetToolTip(Refresh_Button, Localization.MemberChoice_Refresh_ToolTip);
                members_toolBar.Children.Add(Refresh_Button);

                Clear_Choice_Button = new RanetToolBarButton();
                Clear_Choice_Button.Click += new RoutedEventHandler(Clear_Choice_Button_Click);
                Clear_Choice_Button.Content = UiHelper.CreateIcon(UriResources.Images.ClearChoice16);
                ToolTipService.SetToolTip(Clear_Choice_Button, Localization.MemberChoice_ClearSelection_ToolTip);
                members_toolBar.Children.Add(Clear_Choice_Button);

                Levels_ComboBox = new ComboBoxEx();
                Levels_ComboBox.Margin = new Thickness(2, 0, 0, 0);
                Levels_ComboBox.Width = 150;
                members_toolBar.Children.Add(Levels_ComboBox);

                //OK buttonsPanel.Margin = new Thickness(0, 5, 0, 0);
                //Grid.SetColumnSpan(buttonsPanel, 2);
                //OkButton = new RanetButton() { Width = 75, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 10, 0) };
                //OkButton.Content = Localization.DialogButton_Ok;
                //OkButton.Height = 22;
                //OkButton.Click += new RoutedEventHandler(OkButton_Click);
                //buttonsPanel.Children.Add(OkButton);
                //CancelButton = new RanetButton() { Width = 75, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 0, 0) };
                //CancelButton.Content = Localization.DialogButton_Cancel;
                //CancelButton.Height = 22;
                //CancelButton.Click += new RoutedEventHandler(CancelButton_Click);
                //buttonsPanel.Children.Add(CancelButton);

                membersTree.Special_MouseDoubleClick += new EventHandler<CustomEventArgs<CustomTreeNode>>(node_SpecialNodeExpanded);

                // Закладка ПОИСК
                Grid findTab_LayoutRoot = new Grid();
                findTab.Content = findTab_LayoutRoot;

                findTab_LayoutRoot.RowDefinitions.Add(new RowDefinition());
                findTab_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                findTab_LayoutRoot.RowDefinitions.Add(new RowDefinition());
                findTab_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(22) });

                filterBuilder = new FilterBuilderControl();
                filterBuilder.ApplyFilter += new EventHandler(filterBuilder_ApplyFilter);
                findTab_LayoutRoot.Children.Add(filterBuilder);

                RanetButton RunSearch_Button = new RanetButton();
                RunSearch_Button.Height = 22;
                RunSearch_Button.Width = 75;
                RunSearch_Button.Margin = new Thickness(2, 5, 0, 0);
                RunSearch_Button.Content = Localization.Find;
                RunSearch_Button.HorizontalAlignment = HorizontalAlignment.Right;
                RunSearch_Button.Click += new RoutedEventHandler(RunSearch_Button_Click);

                findTab_LayoutRoot.Children.Add(RunSearch_Button);
                Grid.SetRow(RunSearch_Button, 1);

                // Дерево с результатом поиска
                findResultTree = new CustomTree() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
                findResultTree.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(tree_SelectedItemChanged);
                findResultTree.Margin = new Thickness(0, 5, 0, 0);
                findTab_LayoutRoot.Children.Add(findResultTree);
                Grid.SetRow(findResultTree, 2);

                // Количество найденных элементов
                Grid find_buttons_panel = new Grid();
                find_buttons_panel.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                find_buttons_panel.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

                TextBlock m_Find_Results = new TextBlock() { Text = Localization.MemberChoice_MembersFound };
                m_Find_Results.VerticalAlignment = VerticalAlignment.Center;
                find_buttons_panel.Children.Add(m_Find_Results);

                m_Find_Count = new TextBlock() { Text = "0" };
                m_Find_Count.VerticalAlignment = VerticalAlignment.Center;
                find_buttons_panel.Children.Add(m_Find_Count);
                Grid.SetColumn(m_Find_Count, 1);

                findTab_LayoutRoot.Children.Add(find_buttons_panel);
                Grid.SetRow(find_buttons_panel, 3);

                // Закладка ВЫБРАННЫЕ
                Grid mdxSetTab_LayoutRoot = new Grid();
                mdxSetTab.Content = mdxSetTab_LayoutRoot;
                mdxSetTab_LayoutRoot.RowDefinitions.Add(new RowDefinition());
                mdxSetTab_LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(22) });
                mdxSetTab_LayoutRoot.RowDefinitions.Add(new RowDefinition());

                selectedList = new CustomTree() { BorderBrush = new SolidColorBrush(Colors.DarkGray) };
                selectedList.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(tree_SelectedItemChanged);
                mdxSetTab_LayoutRoot.Children.Add(selectedList);

                // Количество выбранных элементов
                Grid selected_buttons_panel = new Grid();
                selected_buttons_panel.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                selected_buttons_panel.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

                TextBlock m_Selected_Results = new TextBlock() { Text = Localization.MemberChoice_MembersSelected };
                m_Selected_Results.Margin = new Thickness(0, 5, 0, 5);
                m_Selected_Results.VerticalAlignment = VerticalAlignment.Center;
                selected_buttons_panel.Children.Add(m_Selected_Results);

                m_Selected_Count = new TextBlock() { Text = "0" };
                m_Selected_Count.VerticalAlignment = VerticalAlignment.Center;
                m_Selected_Count.Margin = new Thickness(0, 5, 0, 5);
                selected_buttons_panel.Children.Add(m_Selected_Count);
                Grid.SetColumn(m_Selected_Count, 1);

                mdxSetTab_LayoutRoot.Children.Add(selected_buttons_panel);
                Grid.SetRow(selected_buttons_panel, 1);

                mdxSetTextBox = new SimpleTextBox() { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, IsReadOnly = true };
                mdxSetTextBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                mdxSetTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                mdxSetTextBox.Margin = new Thickness(0, 0, 0, 0);
                mdxSetTextBox.BorderBrush = new SolidColorBrush(Colors.Black);
                mdxSetTab_LayoutRoot.Children.Add(mdxSetTextBox);
                Grid.SetRow(mdxSetTextBox, 2);

                SelectedItemChanged_Story = new Storyboard();
                SelectedItemChanged_Story.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500));
                SelectedItemChanged_Story.Completed += new EventHandler(SelectedItemChanged_Story_Completed);
                membersTab_LayoutRoot.Resources.Add("SelectedItemChanged_Story", SelectedItemChanged_Story);

                // Кнопка для отображения свойств элемента
                m_ShowMemberPropertiesButton = new RanetToggleButton();

                TabToolBar toolbar = tabControl.ToolBar;
                if (toolbar != null)
                {
                    ToolTipService.SetToolTip(m_ShowMemberPropertiesButton, Localization.MemberChoice_ShowMemberProperties_ToolTip);
                    m_ShowMemberPropertiesButton.Click += new RoutedEventHandler(SowMemberPropertiesButton_Click);
                    m_ShowMemberPropertiesButton.Content = UiHelper.CreateIcon(UriResources.Images.MemberProperty16);
                    toolbar.Stack.Children.Add(m_ShowMemberPropertiesButton);
                }

                this.Content = LayoutRoot;
            }
            finally {
                m_Initializing = false;
            }
        }
        void UpdateGridCells()
        {
            slicerChildren.Clear();
            this.m_Panel.Children.Clear();            
            this.m_DataGrid.Children.Clear();
            
            if (this.Direction == Controls.Direction.Vertical)
            {
                m_Panel.Orientation = Orientation.Vertical;
                List<string> values = new List<string>();
                var enumerator = m_LoadedMembers.GetEnumerator();
                enumerator.MoveNext();
                for (int i = 0; i < this.SlicerHeight; i++)
                {
                    if (enumerator.Current.Value != null && !String.IsNullOrEmpty(enumerator.Current.Value.Caption))
                    {
                        RanetToggleButton button = new RanetToggleButton();
                        button.ButtonId = i;
                        button.Height = double.NaN;
                        button.Width = double.NaN;
                        button.Checked += new RoutedEventHandler(button_Checked);
                        button.Unchecked += new RoutedEventHandler(button_Unchecked);
                        ToolTipService.SetToolTip(button, enumerator.Current.Value.Caption);
                        button.Content = enumerator.Current.Value.Caption;
                        slicerChildren.Add(i, button);
                    }
                    enumerator.MoveNext();                    
                }            
                foreach (var child in slicerChildren)
                {
                    this.m_Panel.Children.Add(child.Value);
                }
            }
            if (this.Direction == Controls.Direction.Horizontal)
            {
                m_Panel.Orientation = Orientation.Horizontal;   
                List<string> values = new List<string>();
                var enumerator = m_LoadedMembers.GetEnumerator();
                enumerator.MoveNext();
                for (int i = 0; i < this.SlicerWidth; i++)
                {                  
                    if (enumerator.Current.Value != null && !String.IsNullOrEmpty(enumerator.Current.Value.Caption))
                    {
                        RanetToggleButton button = new RanetToggleButton();
                        button.ButtonId = i;
                        button.Height = double.NaN;
                        button.Width = double.NaN;                        
                        button.Checked += new RoutedEventHandler(button_Checked);
                        button.Unchecked += new RoutedEventHandler(button_Unchecked);
                        ToolTipService.SetToolTip(button, enumerator.Current.Value.Caption);
                        button.Content = enumerator.Current.Value.Caption;
                        slicerChildren.Add(i, button);
                    }                                            
                    enumerator.MoveNext();
                }
                foreach (var child in slicerChildren)
                {
                    this.m_Panel.Children.Add(child.Value);
                }
            }

            if (this.Direction == Controls.Direction.Both)
            {
                //m_DataGrid = new Grid();
                var enumerator = m_LoadedMembers.GetEnumerator();
                enumerator.MoveNext();
                for (int i = 0; i < this.SlicerHeight; i++)
                {
                    m_DataGrid.RowDefinitions.Add(new RowDefinition() {Height = GridLength.Auto } );                       
                }
                for (int j = 0; j < this.SlicerWidth; j++)
                {
                    m_DataGrid.ColumnDefinitions.Add(new ColumnDefinition() {Width = GridLength.Auto});                 
                }
                int count = 0;
                for (int i = 0; i < this.SlicerHeight; i++)
                {
                    for (int j = 0; j < this.SlicerWidth; j++)
                    {
                        if (enumerator.Current.Value != null && !String.IsNullOrEmpty(enumerator.Current.Value.Caption))
                        {
                            RanetToggleButton button = new RanetToggleButton();
                            button.ButtonId = count;
                            button.Height = double.NaN;
                            button.Width = double.NaN;                        
                            button.Checked += new RoutedEventHandler(button_Checked);
                            button.Unchecked += new RoutedEventHandler(button_Unchecked);
                            ToolTipService.SetToolTip(button, enumerator.Current.Value.Caption);
                            button.Content = enumerator.Current.Value.Caption;
                            slicerChildren.Add(count,button);
                            count++;
                            m_DataGrid.Children.Add(button);
                            Grid.SetRow(button, i);
                            Grid.SetColumn(button, j);
                        }
                        enumerator.MoveNext();
                    }
                }                                
            }           
        }