示例#1
0
        private void Border_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (BorderClicked)
                {
                    BorderClicked = false;
                    Border b   = sender as Border;
                    Grid   g   = VisualTreeHelper.GetParent(b) as Grid;
                    int    row = Grid.GetRow(b);
                    if (g.RowDefinitions.Count == 0)
                    {
                        RowDefinition rd = new RowDefinition();
                        rd.Height = new GridLength(1, GridUnitType.Star);
                        g.RowDefinitions.Add(rd);
                    }
                    RowDefinition currentRow = g.RowDefinitions[row];

                    double currentRowHeight  = currentRow.Height.Value;
                    double splitRowOneHeight = currentRowHeight * (_clickPoint.Y / b.ActualHeight);
                    double splitRowTwoHeight = currentRowHeight - splitRowOneHeight;

                    RowDefinition d1 = new RowDefinition();
                    d1.Height = new GridLength(splitRowOneHeight, GridUnitType.Star);
                    RowDefinition d2 = new RowDefinition();
                    d2.Height = new GridLength(splitRowTwoHeight, GridUnitType.Star);
                    RowDefinition[] allRows = new RowDefinition[g.RowDefinitions.Count + 1];
                    allRows[row]     = d1;
                    allRows[row + 1] = d2;
                    for (int i = 0; i < g.RowDefinitions.Count;)
                    {
                        if (i < row)
                        {
                            allRows[i] = g.RowDefinitions[i];
                            i++;
                        }
                        else
                        {
                            if (i + 2 < allRows.Count())
                            {
                                allRows[i + 2] = g.RowDefinitions[i + 1];
                            }
                            i++;
                        }
                    }
                    g.RowDefinitions.Clear();
                    for (int i = 0; i < allRows.Length; i++)
                    {
                        g.RowDefinitions.Add(allRows[i]);
                    }
                    DeactivateAllSupportBorders(mainGrid);
                    Cursor        = Cursors.Arrow;
                    bordersActive = false;
                }
            }
            catch (Exception)
            {
            }
        }