WPF and graph in the grid? - c#

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.

Related

How to place markers in a DataGrid scrollbar

I have a DataGrid, on the scrollbar I would like to put a marker that shows what items are selected. How would something like this be accomplished?
Have had a look around for similar questions and tutorials with no luck.
In my opinion you should create a ControlTemplate for the scrollbar, in which the PART_Track part should be customized (e.g. by adding small rectangles at the different positions). Here you can find the default style and template for the ScrollBar.
You also have to add a new AttachedProperty to the ScrollBar class, so you have some place to store the positions you would like to mark.
Maybe it is better and easier to create a custom control, which is based on the ScrollBar, and add the required properties there. You still have to create a custom template for that control of course.
And finally, to apply a custom ScrollBar Style only to DataGrids see this question.

Docking buttons in the wpf panels

How can it be done? If there are, for example, four groups of buttons in menu-like panel. How would you dock them to their initial location if the window is resized?
I am trying this using DockPanel and HorizontalAlign, but it seems to only be work for the last button on the right when the window is resized. But how do you dock(anchor) a group of buttons? Maybe put them in border object and use HorizontalAlign for it? Is there more elegant way to do this?
To summarize the comments: I don't know your background but it seems you are used to another way of UI design where you do not explicitely have to specify grouping etc in code. While that might seem more elegant, it is not: the designer generated code is awful and the whole system is not as flexible nor srtaightforward as what WPF gives you..
With WPF you get a clear one-to-one relationship between your intent (treating buttons as a group within a layout) and the actual code (put the buttons in a stackpanel/grid/...). Or draw a border around buttons and organize them vertically within the border vs in xaml use a border with a stackpanel inside. It won't get any more elegant than that.
Read up on WPF layouts and once you'll get a grip of it you will quickly see that it is rather powerful and beatiful at the same time. I found this tutorial pretty helpful when just starting with layouts. And google provides lots and lots and lots more information, as usual.
Like stijn said, put the buttons in a Grid or a Stackpanel and you'll be fine.
You may not think it's beautifull, but it's the best solution for your problem.

Any way of achieving a 'permanent tooltip' type of feature in WPF?

Basically I need a nicely formatted stackpanel to appear over a control - permanently. This stackpanel will overlap other controls if needs be. So what I'm trying to say is that it's equivalent in web design would be the highest of z indexes (not sure if this applies to wpf - I'm rather new to it).
There is a second layer called the Adorner Layer that you can use to...adorn other controls. When you add UI to the Adorner Layer, it sticks with the control it's adorning and always has the highest z-index over regular controls.
BTW the documentation says it's not possible to add an adorner using XAML, but through the magic of attached properties (or blend behaviors), it is indeed possible to use XAML elements to create adorners. I don't have an available sample but this Codeproject article gives a good walk through
Looks like you're looking for an Adorner.

Simple WPF Control Questions

Just ran into a bunch of random but probably very simple questions while learning to work with WPF. If anyone can answer any of these it would be most appreciated.
I have a Rectangle that I styled to my liking, and then a StackPanel that I am actually placing the content (bunch of labels) in. It looks like Rectangle doesn't have a closing statement so how can I make it the parent of the StackPanel (I want the panel to move with it)?
I need to display text (labels) in a table form. It will only be two columns, and 8 rows (row count may change). I initially looked into just using a Grid, but as this is a intended for Layouts, it didn't work as expected. I also checked out DataGrid, but this seems confusing and overly complicated for my needs. Is there any simple Table style element I can use?
I have some Animated Expanders and I want to give the other UI content elements in my application a similar looking title bar. I haven't seen any sort of element for this, so I am wondering if I just need to use a Label or something and style it as close as possible to match, or if something already exists that I should use instead. If I need to use a label, what is the proper way to group/attach it with the element that it is the title bar for?
Do any controls exist for WPF that would allow for a Mac style menu bar? Something similar to where the icons move and expand as they are mouse over.
I have a grid that has two expanders (one above the other) with Height="Auto", and two rows set to Height="Auto" so that when the top is minimized, the bottom one moves up to close the gap. I am using a MinHeight right now to make sure they are at least somewhat expanded, but I would like to make them take up the full 100% of the Grid height. What should I do for this?
A rectangle cannot have child content, a better approach might be to use a Border, you can use this as that parent of your stackpanel, applying a Background and BorderBrush to make it look like a rectangle.
For a simple table layout Grid is the way to go. Is your problem that you need it to be dynamic? If so, you can create multiple grids with SharedSizeGroup on the columns to make them look like a single grid. See: How to align separate Grids created via templates along their columns / rows?
Learn about creating your own templates!
Not that I know of, but it would be relatively simple to do, create a storyboard that scales the item on mouse over.
No idea ... running out of steam!
As Andrzej Nosal mentioned, these really should be separate questions!

I would like to learn about creating graphic objects at Runtime in c#

I would like to learn about creating a program that I could draw simple shapes and be able to select them for editing - like resizing, order of display, color change. Is there an online resource that someone knows of that would help me reach my goals.
thanks
"GDI+" is what you are looking for. You can start here: http://msdn.microsoft.com/en-us/library/da0f23z7.aspx
A sneaky way I used to do it was to create a custom control, remove the background from it and paint my shapes and sizes on it. Then, you can easily implement selection (override OnClick), dragging and resizing (OnMouseDown, OnMouseMove, OnMouseUp). You can then implement options like color, etc. by means of a property (see Browsable attribute and property get/setters) and a PropertyGrid control.
Anything beyond that, though - Bezier curves and such - would need something a tad more advanced, though.
The alternative is to only use such controls for the sizing handles, and do all the drawing on one central canvas - the only drawback then is figuring out how to select a shape on the canvas.

Categories

Resources