I would like to know if there are any inbuilt controls in C# with which I can program location grid maps on a X/Y Plane.
The only thing that comes to mind is the grid view. You could arrange the columns and rows into a regular grid.
Besides that, .Net makes it very easy to place controls dynamically into containers. You could also do manual drawing which is very straightforward.
Here is an example of grid painting.
And here's an example of dynamically adding controls to a form.
Related
I want a grid in my page to have a single column in portrait mode and have two columns in Landscape mode. Some of the content should move to the second column when the device is Landscape. I've tried to do this but couldn't.
I'm doing everything from code behind. Generating the grid, adding children etc. When Orientation changes, I destroy the current layout and create a new one. The problem with this approach is, any entered data will be gone. It's a huge code and not possible to put here. I want this layout change to happen automatically. So, any data that is entered is preserved after the orientation change.
Any help would be appreciated.
The trick is to have one grid that accommodates both states. You can use VisualStates to assign different Grid.Row, Grid.Column, Grid.RowSpan and Grid.ColumnSpan values to controls. This is done using Blend and is declarative in XAML. you give each state a name. In the code you detect size change of the window to trigger the different states using the VisualStateManager.
You can also do this without VisualStates. In that case in the event handler of the SizeChanged you have to set the appropriate values for all the controls yourself.
In Windows 10 UWP it got much simpler using RelativePanel. You can position controls in a more flexible way then with grids.
Martin
I have the following application:
I am developing a Windows Store app in which I need to show a big grid filled with buttons. The content of the buttons are some numbers and when I click any of them, I open a Popup with editor, where I edit those numbers. For that purpose I use a GridView, I put an ItemsWrapGrid as ItemsPanel. This makes the grid look exactly as I need it to look. I put the GridView inside a ScrollViewer, because I need to scroll the grid in both directions, since it has a lot of elements. Also I need to have the pinch-to-zoom effect that the ScrollViewer gives out of the box. I need to change the ItemsSource for that GridView when the user chooses different source in a ListView next to the GridView.
The problem:
Putting the GridView inside the ScrollViewer breaks the Virtualization inside and this has a major impact on my performance. When I switch the ItemsSource of the GridView, it takes more than 3-4 seconds for the rendering and during that time, the UI is frozen.
My question:
How can I keep the awesome stuff that the ScrollViewer gives me and also keep the virtualization? Because when I remove the ScrollViewer, changing between the ItemsSources happens almost instantly.
Any idea?
You'll be best off implementing virtualization yourself since you're trying to use the GridView far from the use cases it was designed for.
Put a Canvas in a ScrollViewer that does both pan and zoom and handle view change events on the ScrollViewer by laying out item containers inside and around the viewport. Avoid unnecessary changes too, so keep containers in place if they are to stay realized between view change events and recycle containers that are leaving the viewport neighborhood.
I am trying to design a UI in C# . I come from Java background and am familiar with the different layout managers in Java.
So what I am trying to do is:
I have a Pane. To this pane I wish to add controls one below the other. In Java I would have used a BoxLayout (Y-Axis), and then just added the controls. Also the individual controls/containers could have been further customized by using different layouts for each individual container.
How do I do this in C#?
What I need to do is:
1)Add controls one below the other. Each individual control can be a collection of smaller controls.
So what I can have is something like:
Control 1 here
Control 2 here
Control 3 here
Each control can have its own layout, say BoxLayout on X axis and so on. How do I do all this?
PS: I am using WINFORMS.
I will take a stab that you are building WinForms, and suggest you look at the following controls, which are similar to the Java layout managers;
Panel
FlowLayoutPanel
TableLayoutPanel
A Panel will let you place controls arbitrarily within it, and you use the Dock, Anchor and Location properties to position each child control.
A FlowLayoutPanel will do what you are asking if you set the flow to 'TopDown', but everything will be left-aligned and that can't be changed I believe.
A TableLayoutPanel is going to be the most useful to you I expect. Just create the panel with 1 column, and add each control to a row. The rows can be set to AutoSize to their contents to give you the closest match to a BoxLayout I think.
I would like to draw a linechart-like graph in a grid column in WPF (C#).
Something like this:
Obviously to make it look good I need to style the grid to not have cell borders, but that's not a problem. The problem is how would I even approach this? There's no column type that sounds good and since the graph is all connected it feels like painful to implement.
Not very sure why you need Grid control, actually here. May be ListView would enough for you ? It's much more lightweight then Grid control.
To draw that stuff you could
make use of Adorners in order to draw something semitransparent over the items.
or
Define a style for the control (ListView or Grid) where on left side you have Canvas element which overlaps the items collection of the control.
or
can try to use very customizable TreeControl like from example from Josh Smith, but naturally with your changes.
Good luck.
First of all, here's some concept art for how this custom list control must look:
http://img816.imageshack.us/img816/1088/customlistctrl.png
Each list item is fairly complex and turns into an "edit interface" when the mouse hovers over it. I also have PNG image files for every skinning detail of this thing, including the scroll bar.
What is the best approach to get started implementing this? Would I create a custom control and simply render all of this in GDI?
Could I make the list control a transparent clip region with a scroll bar? For the individual list items, would I simply use a textured panel as the backdrop for each item and place existing .NET forms (like combo boxes, buttons, edit fields, etc) as children of that?
I've never had to create something this detailed before.
If you want your control to look exactly like the given picture (which is nice), you will end up drawing much of it, if not all of it, yourself. One possibility is to subclass each control being used and override the OnPaint method to do your custom drawing. This assumes a design where everything in your picture is an individual control.
I myself might make each row a separate UserControl-derived class, perhaps with an internal constructor so users of your control can't create the row directly. Within your SkinnedListRow class (or whatever name), you could have each of the subcontrols. By the looks of things, the row contains three controls that display numbers and one that displays any kind of text.
For the editing portion, derive another UserControl that contains all the controls you picture. Both the display controls and the editing control are owned by the SkinnedListRow from above, so it knows how to load data from one set into another.
You have a good amount of work in front of you, but your idea looks nice. Good luck.