i have a program in C#, wpf.
i have a canvas and on the canvas exists many ellipses that are moving randomly.
Can i add text to each ellipse for example the position of the ellipse ???
Of course, create a user control. The xaml of that user control is a grid that contains your ellipse and your textbox that you set up like you want. Then define the PropertyChanged notifying properties you need, like X,Y, and maybe other text property. Then bind your user control's xaml (Canvas.Top/.Left) to your user control's properties, and you're done.
Related
Using UWP XAML, I am trying to recreate this textbox UX from Postman whereby it pops up above all other elements in the app to display the full text: https://streamable.com/avrixo. I've almost fully recreated this UX, but I am having trouble bringing the textbox to the "front" of the app while the textbox is inside a listview.
What I have tried:
I have tried creating a UserControl for a custom text box with Canvas as its parent. Like this:
<Canvas>
<TextBox/>
</Canvas
I added some event handling to change the text wrapping and the Canvas.Zindex attached property of the textbox when the user focuses on it (I've tried setting the z-index to 1, 10, 100, and 1000000). However, I found that as the textbox expands vertically, it remains "behind" the listview item below it no matter what z-index I give it.
How can I bring the textbox inside a listview item to the "front" of the UI?
I don't think your problem is with z-index (per say) in this case. The problem here in the ListView is that each ListViewItem has it's own bounds, so the TextBox is being clipped by the bounding box of the item. You can double-check the bounding areas with the Visual Tree tools at least to confirm that's the issue.
If you don't want the ListViewItem to expand in size to match, I can see two options. When the user clicks to edit, you put a 'fake' TextBox (bound to the original in the ListView or the data item) either in 1) a Pop-up that you display or 2) in an overlay that's part of your page's XAML that has the textbox.
You can grab the selection state and cursor positions and such from the original textbox, and move focus to the new one and mirror that same state.
That's the approach I think I'd take.
I have a canvas where I need to draw a grid, but behind child controls. I tried to create a new adroner and just add it to the canvas, but this adorner is displayed over child controls. How can I make this adorner be behind canvas' children? I don't want to draw this grid in the OnRender function of the canvas...
Clarification: grid is not a control. it is a painted grid or net on the canvas. it is created for making position elements easier.
One way to do this is to use a TileBrush as the Canvas.Background and set the TileBrush to an appropriate grid pattern.
An Adorner can only ever be on top (it allways has the highest zindex). You need to look at another solution to your underlying issue
Use the Panel.ZIndex Property to set the order elements get displayed on the z-plane.
In a WPF application, I'd like to create a textbox dynamically which will show in front of the application and be able to freely set its location by pixel. (The textbox is going to follow the mouse cursor).
This was easily done in Winforms on the fly but WPF makes things.. a little bit weird when it comes to setting a control's location by pixel since I have to add the control as a child of a container. I'm aware this is certainly doable on Canvas, but what I actually have is a dockpanel with a richtextbox to the left and a datagrid to the right.
So what are my options here? Do I have to use canvas? Can I get away with using dockpanel (or grid) to implement what I want here?
You can use a Canvas or a Grid. If you use a Canvas, set the Canvas.Left property and the Canvas.Top property. If you use a Grid, you'll need to set a size for your TextBox, set the HorizontalAlignment to Left, and VerticalAlignment to Top. To change the location of the TextBox, assign it values for MarginLeft and MarginTop.
I'm writing a 2D graphics tool in C# and WPF, and I'm using Adorners on the Shapes drawn to Canvas.
I'd like the adorners to highlight when a shape is considered "selected", which I'm currently doing using MouseDown and MouseUp events.
However, the user can select multiple shapes, so not all of the shapes will receive both of the mouse events.
I have a class that manages the drawing, which holds a List of the selected shapes. What is the best way to give the adorners access to this data, so they can see if their adorned element is selected?
Some thing's I've considered:
Making the List global - bad idea
Sub-classing each shape to add a "selected" property - would require changing all references to the shapes in my class
You can make an attached dependencyproperty you set on your shape - then you can set that property when you select one.
The adorner can have a visibility binding to the property on the shape so you get visibility set automatic.
You can also use the Tag property on the shape to store values - that is the old way of doing it :)
I'm currently writing a marquee control for WPF. The control consists of an ItemsControl, with TextBlock as the DataTemplate element of choice. The ItemsControl is the target of a Double Animation, which manipulates the Canvas.Left property.
What I would like to do is create a "circular mode", which will allow the marquee to dynamically add an item to its' tail whenever the last item has scrolled into view. That way, the marquee will never appear empty.
How can I detect when a TextBlock has "scrolled" into view (effectively become visible) as a result of the animation?
It might work that you check whether the ItemControl's ActualWidth property is greater than the current Canvas.Left value of your TextBlock.
To get the change event, have a look at this SO: How do I handle Canvas.Top change event in WPF?
Maybe it is useful to keep a references to the last control that was added to the tail of your marquee, so that you can remove the event handler once the control is scrolled into view and attach the event handler to the TextBlock that is then added to the tail.
It would be nice to be able to draw something for a better understanding. If anything's unclear (technically or conceptually) ask, ask, ask... :)