Adding grids in XAML - c#

I am designing a graphical application in WPF and net 4.5. I want to use the MVVM pattern and to not break it I would like to use as less code behind as possible.
The application should start with a window that contains a line graph, that is easy enough :)
When the user chooses so he can add another line graph, or a data pane. And that indefinitely, as shown in the picture below.
The user should be able to resize these windows. There will also be some sort of scrolling in the graph panes and all the line graphs there should scroll together.
I was thinking to use a grid for this. I would be able to accomplish this hard coded, but I am wondering if it is possible to do this solely relying on XAML.
Thanks

Related

How do I make draggable controls in WPF?

I am trying to find a way to create custom controls which lets the user drag them around on screen. This illustration shows roughly what I'm after:
So, this is basically a node network, where each node can have an arbitrary number of children and exactly one parent node. The connections between the nodes also has to follow them when they move, and bend appropriatly. I would also like all nodes to move when dragging the "canvas" behind them.
I know this is a lot of information, but basically I'm wondering if this is possible (and not too difficult) to achieve with WPF, and if it breaks with the philosophy of WPF to use it in this way. Is there a better way than using WPF for this? I've done a lot of research and can't find much info doing these things with it. Also, what is the most common ways to do this in Windows applications using .NET and C# if this seems way off?

Code-Folding Code on RichTextBox using TreeView

I'm currently developing an IDE and Im working on Code-Folding codes now .
I'm thinking to use a TreeView as for it has a collapse and expand property but i dunno/not sure how can I implement it on RichTextBox .
Even an Initial Code showing if interaction within RichTextBox and TreeView will be much appreciated .
like:
{
}
then RichTextBox will have a line indicating till where to collapse .
Thanks a lot in advance!
It doesn't seem feasible to include a TreeView inside a RichTextBox. From my experience, building something atop the RTB is quite problematic and doesn't render the desired result without having quite a lot of quirks.
I suggest taking a look at the Fast-Colored-TextBox:
http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
Or possibly building a similar control from scratch (if you too suffer from NIH) instead of attempting to extend the RTB.
If you really need your own code editor you should really think about taking Avalon Edit. It is able to rebuilt an Visual Studio Editor. So it has all you feature you need (and more).
I know it is a WPF component and not winforms. But it is quite easy to host a WPF control within winforms. So better take this route, cause trying to interweave a tree view with a rich text box will never match exactly what you like (just think about finding out the pixel size of a textline if you are using different fonts or how to determine line wrapping).

Breaking up an all C# WPF application into XAML for one of its UI controls and C#

This is a broad question, I am aware. However, I have been trying to make a modification in a C# source code to enable a ToolboxControl UI control's right hand border to respond to a mouse drag. In other words make the control size bigger by grabbing the right hand boarder and dragging it to the right. I Have not been successful. So I am thinking if I incorporate a XAML file and create the ToolboxControl in XAML, maybe I would have more control in manipulating the ToolBoxControl.
I dont know how to break up a pure C# WPF code into C# and XAML.
In a nutshell, The problem I am dealing currently is that there is already C# code developed by other developers to perform certain function. I am using the existing C# code but I believe if I move some of the UI functionality from the C# into a XAML file, I would have a better handle on adding some of the needed UI features to the original program.
So you see my problem is I am not starting from scratch. I need to use an existing C# code and break away some UI functionality of it nd put it in a new xaml file. Do you have any ideas about any place that that has been done?
I am looking for any repsonse that leads me to a conversation thread or a sample. In other words I dont know where to start from. any useful guidance is apprecaited and would be marked as an answer.
Check out this article.
At its simplest, you will need to add an invisible (or not) drag handle to the right hand border of your control, then adjust the control size during the drag events raised by that drag handle.
Here is another article showing a similar concept expanded to an entire diagramming system, which includes the resize behavior you mentioned.
You may be able to define a style for what you are trying to accomplish. I wouldn't worry too much about breaking apart the C# from the XAML as that is a nice to have but not nec

Ways to create a dynamic technical drawing inside a Win Forms Application

I've got a c#, .net 4, mdi Windows Forms application which configurates a product. The product is one of a kind, it always looks different but similar.
I would like to create a simple technical 2D drawing which is created and shown based on the user input. My idea is, that the user enters the product data in one mdi form and the drawing is shown in another mdi form. The drawing should be created in its own thread, so the user does not have to wait for it.
About the drawing:
It should contain lines and rectangles with different colors, filled and unfilled. Some lines/rectangles have text information next to it, f.e. to show the dimensions or a name.
I am not sure which way i should go to create the drawing. My first ideas were to use Microsoft Visio Drawing Control or just to draw on a Form. But i am not sure if thats really the way to go.
I am grateful for any suggestions. Are there any other good libraries for simple 2D technical drawings? Is Visio or Windows.Drawing the way to go? Any other ideas?
/edit: example drawing:
/edit2: it would be useful, to highlight shapes programmatically. Also useful would be a shape mouse over event.
I used WPF as suggested and host it in ElementHost. It works pretty good, polygons have mouseover events, so you can highlight/select them and show detailed information about a linked object.
There are lot of tutorials to get started with drawing polygons and stuff. A bit more tricky was to implement zoom and drag features. Therefore i found this example which i can highly recommend: WPF simple zoom and drag support in a ScrollViewer

How to accomplish different states of view in WPF Apps

I have an idea for a personal project. And I know one way of accomplishing it in Windows Forms (which I no longer wish to use). Basically I could (in WinForms) just draw everything onto the screen (Form) and then when I need to switch views/states of the application, just redraw the new stuff in the old stuff's place.
But how can we have different states in WPF? Is there a "right" or "proper" way of doing this? Is something like this covered somewhere in the docs?
I'd like to do my own searching, but I have no idea what exactly to look for, and current attempts at finding the right information, so far have yielded no helpful (or even relevant) results.
Any help at all will be greatly appreciated. I am new to WPF, but have been making a lot of progress this past week!
Thank you!
P.S.:
I just thouhght of something. If the solution was to draw what is needed for one screen, and when it is time to display the next screen, just dispose of/hide everything and create/display the new stuff, then how would we get around this? Because we can't/shouldn't change XAML markup at runtime, can/should we? :/
Not sure how you drawn your views/states in WinForms (direct painting on a Graphics object?).
The closest to what you're describing is the VisualStateManager. You can use it to statically define several visual states inside a single XAML and transit between them (using a smooth animation if you want).
If what you've done was show different Forms with Show/ShowDialog(), then the equivalent would be to use different Windows and Show/Hide them.
If you just cleared/added Controls to your form, then you can do just the same in WPF. Most Controls in WPF have a Content or Children property instead of Control.Controls in Forms.
I don't know if I understand what you really want. But here are my thoughts:
You can use several Windows and Show/Hide them accordingly
You can use the Frame/Page functionality in WP (MSDN)
if you really need to you could load your XAML and remove the topmost content in your Window and replace it with the loaded content
You could use the VisualStateGroup functionality to change the appearance of your current window
I think you will be happy with the second solution

Categories

Resources