Ejemplo n.º 1
0
        private void DrawLauncher()
        {
            // 탭부터 만들기
            foreach (DataRow row in tabs.Rows)
            {
                TabItem tab = new TabItem();
                tab.Header = row["Name"];
                tab.Tag    = row["Id"];
                Grid grid = new Grid();
                tab.Content = grid;
                tabControl.Items.Add(tab);


                for (int r = 0; r < rowCount; r++)
                {
                    grid.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Star)
                    });

                    for (int c = 0; c < colCount; c++)
                    {
                        if (r == 0)
                        {
                            grid.ColumnDefinitions.Add(new ColumnDefinition()
                            {
                                Width = new GridLength(1, GridUnitType.Star)
                            });
                        }

                        // col 선택 후 버튼 삽입
                        MButton button = new MButton()
                        {
                            TabId = tab.Tag.ToString(),
                            Row   = r,
                            Col   = c,
                        };
                        button.AllowDrop = true;
                        button.Click    += new RoutedEventHandler(Button_Click);

                        button.ContextMenu         = this.contextMenu;
                        button.ContextMenuOpening += Button_ContextMenuOpening;

                        button.DragEnter        += new System.Windows.DragEventHandler(Button_DragEnter);
                        button.Drop             += new System.Windows.DragEventHandler(Button_Drop);
                        button.PreviewMouseDown += new MouseButtonEventHandler(Button_PreviewMouseDown);
                        button.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(Button_PreviewMouseMove);
                        button.PreviewMouseUp   += new MouseButtonEventHandler(Button_PreviewMouseUp);


                        Grid.SetRow(button, r);
                        Grid.SetColumn(button, c);
                        grid.Children.Add(button);

                        // button 가져오기
                        DataRow rButton = buttons.AsEnumerable().FirstOrDefault(dr =>
                                                                                dr.Field <string>("TabId") == row["Id"].ToString() && dr.Field <Int64>("Col") == c && dr.Field <Int64>("Row") == r);
                        if (rButton != null)
                        {
                            button.Text      = rButton.Field <string>("Name");
                            button.IconImage = IconManager.ByteToImage(rButton.Field <byte[]>("Icon"));
                            button.Path      = rButton.Field <string>("Path");
                        }
                    }
                }
            }
        }