I have an application that loads a XAML file, and shows it in a ContentControl. What I also want to implement is a way to go over the XAML code that was loaded to the control and populate a listbox with the names of the Canvases I find.
The main task of this tiny application is to enable the user to change colors of specific canvases and their elements. Meaning that I have, for example 10 canvases, each containing some <Path> elements. I want to give the user a list of the canvases that were found in the XAML code, and for each canvas the user will be able to change its fill color (for example), if the user changes the fill color of a specific canvas, the child elements of that canvas will change their "Fill" attribute to the selected color as well.
I didn't find a way to iterate through the Canvases or the Path elements, so if anyone have a way to do this I would be glad to hear.
Thanks!
You seem to need to traverse the logical children tree of a given control. For this, you need to use LogicalChildren property recursively.
You can find more information on the element trees in WPF here.
Related
I have a chart with multiple chart areas and I want to have a listview where the user checks different signals, that are being plotted in the areas.
Since I want some signals to be displayed in more than one chart areas, I need the listview to reset every time the user selects a different chart Area.
To achieve this I think it is a good idea to create a new listview every time the user selects another chart area and bring the new to front.
My question is , how can I create multiple listviews at the exact same location, and also if someone has a better idea to this.
As you know, you can define the listview in code and do all the styling by hand or you can create a customControl for that.
But then, when the load event of your main form is fired, you create all the listview/customListViewObjects that you need and place them in the same location with the same size by setting their Location and Size property. Finally, you can use BrintToFront() on the required listview when an area is selected.
There are some other ways, but they aren't beautiful in winforms.
A) you can create a tab control with N tabs, then place a listview in each tab and set the tabControl style to the tab header/title is not shown. But as far as I remember, the tabControl will add a border frame that your cannot get rid of.
B) If you don't have many areas and its number is not going to change, you can create the listviews manually in your form editor, and place them wherever in your form (with the appropriate parent, of course). Then in your load event, you can set their location and size properties to the one you need. This is kind of ugly and you may see the controls moving when the form is loaded if you are not careful.
On the other hand, you can just have one listview and then, when the area is clicked you can reload all its child controls for the different signals.
I hope make text that always visible in screen, see my gif
I hope text in FloatingTextCanvs visible but it's covered by button, I find the later create ui object will cover previous objects, can i change text object's index to make text always visible?
To display one canvas in front of the other, you want to change the Sort Order property on the Canvas component to be higher than the other canvas.
If you are dealing with two separate canvases then you can set their sort order to determine which one appears on top.
If you are dealing with two UI elements that are children of the same canvas, then their physical arrangement within the hierarchy determines which one appears on top. The child at the top of the hierarchy will appear underneath the other elements. For example, in the following MainMenuCanvas, the Background image will appear behind the Text.
I have an app where a user can manipulate around with elements chosen from a list, this is done by clicking the list element and the element is added to a canvas.
During a user testing of the app. People found it not to be intuitive since they wanted drag and drop. I have found several links describing how to implement this for WPF, i.e. not for windows Phone.
Trying to replicate the code from a msdn project i ended up with problems that I cannot get the same information about the elements from DragEventArgs.
So what I want to accomplish is user can drag an element in a listbox to a canvas. I have tried in the Viewmodel but missing information in DragEventArgs, like e.Data and e.Source. I have also tried in the xaml.cs file with no success.
Any help is appreciated.
Idea
create a copy of your element when it's selected,
add the copy as a child of your canvas,
set the copy's x,y coordinates to match the selected element's location,
CaptureMouse() on the copy.
Of course on Windows Phone Manipulation delta should be used to move it instead of capture mouse. I am able to drag an element around inside the Canvas after it was added by a Click event. But I can't seem to get drag from list to work. The bullet points above is a method I have and are trying but without any success so far.
There exists no samples or anything to accomplish this. I have contacted people at msdn, and Microsoft, without any success. I am trying to build a sample but so far no success.
Edit
So what I did to solve this issue: first the problem graphically
In words dragging an element from listbox to a Canvas. SO what I did I added handlers to the listbox like this, in the view:
MyLB.AddHandler(UIElement.ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(MyLB_ManiStarted), true);
MyLB.AddHandler(UIElement.ManipulationDeltaEvent, new EventHandler<ManipulationDeltaEventArgs>(MyLB_ManiDelta), true);
MyLB.AddHandler(UIElement.ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(MyLB_ManiCompleted), true);
Furthermore I add an extra canvas, here after referred to as Canvas2, that stretches behind the ListBox and Canvas.
The only difference between the two canvas' are the size, else they have the same itemscontrol but with different observablecollections binded to the canvas'.
In ManipulationStarted I find the element and add a new one to the observablecollection of Canvas2. Furthermore I Set the zindex of Canvas2 to be infront.
I then tap into the delta event to move the element around on Canvas2
in ManipulationCompleted I check if the element is inside the bounds of the first Canvas.
I then delete it from Canvas2, and move Canvas2 to the back, using Canvas.SetIndex(UIElement, zIndex)
Depending on the bounds check in (3.) I then add it to the first canvas. And everything works.
But I do not use the drop feature or the related events since it did not seem to help because of the missing dragable element. But this works :)
Silverlight on WP7 does not support drag and drop – at least not fully. It supports drag but not drop.
Anyways you can try something with the following example,
WP7 Drag & Drop Example
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 need to build a WPF control that looks somehow similar to this:
alt text http://img251.imageshack.us/img251/6857/circle.png
Where each color should be clickable and resizable (or selectable).
This control will be used to set modes on the hours of a day.
I've thought about making 24 buttons that would be arranged in a circle:
alt text http://img684.imageshack.us/img684/2184/buttonsk.png
Another idea was to draw a complete circle and calculate user mouse click's position for the selection and draw several circles to represent the data.
Any other/better ideas on how to build this?
(please excuse my poor drawing).
I think you would get odd edge-effects with multiple overlapping or touching controls. So I would make a single custom control to do this. It would convert the mouse position on button down to a slice, and then do the appropriate action.
With a single control, you could also come up with a rational way of dealing with keyboard input and for showing selection and allowing for multi-select behavior.
It sounds like you want a customized ListBox (multiple items that are selectable/clickable). For the layout you would want to use some type of RadialPanel as the ItemsPanel. You probably also need to change the ItemContainerStyle to make your ListBoxItems look like what you have above, probably with some triggers to change colors based on selection state. Depending on what behavior you need from your items you may need to create custom ListBox/ListBoxItem derived custom controls but in a lot of cases the built-in behavior will get you a long way. To reuse it as a single unit you could wrap up the ListBox with its 24 hour items and customized templates in a UserControl and expose the selection data in whatever form you need as a Dependency Property (like an IEnumerable of the data items representing the selected hours).
Does that help you get started?