icsharpcode / WpfDesigner

The WPF Designer from SharpDevelop
MIT License
949 stars 251 forks source link

GridSplitter For Sticking Components #46

Closed khalili-mahdi closed 6 years ago

khalili-mahdi commented 6 years ago

in DesignSurface there is one horizontal and vertical splitter in middle of page , which controls sticking to them i want 4 of those guys,which can be resized here is my wrong code :)

            Engine1.DynamicGrid.NumRows = int.Parse(FormXML.Attribute("ROWS").Value.ToString().Split('*').First());
            //Engine1.DynamicGrid.NumRows = 4;
            Engine1.DynamicGrid.NumRows += Engine1.DynamicGrid.NumRows - 1;
            Engine1.DynamicGrid.NumColumns = int.Parse(FormXML.Attribute("COLS").Value.ToString().Split('*').First());
            //Engine1.DynamicGrid.NumColumns = 4;
            Engine1.DynamicGrid.NumColumns += Engine1.DynamicGrid.NumColumns - 1;
            //Engine1.DynamicGrid.ShowGridLines = true;
            for (int i = 0; i < Engine1.DynamicGrid.NumColumns; i++)
            {
                if (i % 2 != 0)
                {
                    //gridcolumnsplitteradorner or gridrowsplitteradorner
                    //designerSurface.dsingnpanel.adornerlayer =>  adornerpanel.children.add(splitter);
                    //gridadornerprovider.splitterlist.add(splitter);

                    GridSplitter gs = new GridSplitter();
                    gs.ResizeDirection = GridResizeDirection.Columns;
                    gs.Width = 3;
                    gs.HorizontalAlignment = HorizontalAlignment.Stretch;
                    Grid.SetColumn(gs, i);
                    Grid.SetRowSpan(gs, Engine1.DynamicGrid.NumRows);
                    Engine1.DynamicGrid.Children.Add(gs);
                }

            }
            for (int j = 0; j < Engine1.DynamicGrid.NumRows; j++)
            {
                if (j % 2 != 0)
                {
                    GridSplitter gs = new GridSplitter();
                    gs.ResizeDirection = GridResizeDirection.Rows;
                    gs.ShowsPreview = true;
                    gs.Height = 3;
                    gs.HorizontalAlignment = HorizontalAlignment.Stretch;
                    Grid.SetRow(gs, j);
                    Grid.SetColumnSpan(gs, Engine1.DynamicGrid.NumColumns);
                    Engine1.DynamicGrid.Children.Add(gs);
                }

            }

            RootItem.Children.Add(Engine1.DynamicGrid);
jogibear9988 commented 6 years ago

I don't understand your question!

khalili-mahdi commented 6 years ago

there is yellow borders when ever you move controls inside designer , show up in middle of designer and borders of designer which controls border stick to it , i think they are splitters if i'm wrong let me know you can add them to designer by clicking on borders i think , i want to create them dynamically instead of using gridSplitter because they hold controls inside and dont let control to move out

jogibear9988 commented 6 years ago

This are Adorners wich are shown for each Grid Column or Row.

Means If yo add a new Column to grid.columndefinitions you will see it

        var desItem= MyDesignerModel.Instance.DesignSurface.DesignContext.RootItem;
        desItem.Services.Selection.PrimarySelection.Properties.GetProperty("ColumnDefinitions").CollectionElements.Add(desItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition(){Width = new GridLength(200)}));
        desItem.Services.Selection.PrimarySelection.ReapplyAllExtensions();
khalili-mahdi commented 6 years ago

Ty for your Great Work

khalili-mahdi commented 6 years ago

i did this

var desItem = designSurface.DesignContext.RootItem;
            for (int i = 0; i < 5; i++)
            {

                desItem.Properties.GetProperty("ColumnDefinitions").CollectionElements.Add(desItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition() { Width = new GridLength(200) }));

            }
            desItem.ReapplyAllExtensions();

its giving me error in DesignItem.cs in AddBehavior 'An item with the same key has already been added.'

jogibear9988 commented 6 years ago

are you using newest source code? I think I did a fix cause of this error a few days ago

khalili-mahdi commented 6 years ago

yeah i have latest source

public void AddBehavior(Type behaviorInterface, object behaviorImplementation)
        {
            if (behaviorInterface == null)
                throw new ArgumentNullException("behaviorInterface");
            if (behaviorImplementation == null)
                throw new ArgumentNullException("behaviorImplementation");
            if (!behaviorInterface.IsInstanceOfType(behaviorImplementation))
                throw new ArgumentException("behaviorImplementation must implement bevahiorInterface", "behaviorImplementation");

            _behaviorObjects.Add(behaviorInterface, behaviorImplementation);
        }

it stucks at last line of this function

jogibear9988 commented 6 years ago

Could not reproduce

jogibear9988 commented 6 years ago

it works on my sample

jogibear9988 commented 6 years ago

look here: https://github.com/icsharpcode/WpfDesigner/commit/1292332879ca98eded2d24905a21f188f6640b32