Need to show usercontrol on the top in WPF - c#

I have a user control that I am using for some purpose and it's movable on the screen. Actually I am creating an application using Leap Motion. SO wherever I move my figure on the screen a big circular cursor moves accordingly. But on some place it gets cut off or I would say it gets hide or overlapped due to some other controls. So I want to know, how can I placed it on the top of the mainwindow view. Is it possible using adorner layer? If yes, So can you please tell me how to do that in WPF?
I found few examples on net but they are creating a rectangle or some thing on adorner layer using drwaingcontext object, however I just need to show my user control on the top.
Please give me some idea
Thanks & Regards,
Vinod

You shouldn't need to use the Adorner layer to simply show a UserControl on top of other controls... of course that depends on exactly what is 'overlapping' or hiding it. If they are just other UI controls, then you can fix your problem in two ways.
The first is to simply declare your UserControl that you want to be on top of the other controls at the bottom of the XAML, eg. define that element last.
The second solution is to use the Panel.ZIndex Attached Property to place that element above all others:
<UserControl Panel.ZIndex="10" />

Related

XAML advice for implementing tab-bar

Is it possible to achieve the following visual effect in .NET MAUI/XAML:
The main concern is the outline (or lack thereof on the bottom) of the selected tab and the underline of the unselected tabs.
The goal is to be able to define an arbitrary number of Tabs for the application.
Is this possible with XAML alone?
Any help would be greatly appreciated
If I had to create custom controls I would go with the GraphicsView.
Create a custom control Tab with a canvas that draw it in function of it state, you can use StackLayout to stack them and TapGestureRecognizer to manage clicks events.
One of the main problem of a GraphicsView is that you can't attach click event to shapes you are drawing (one solution there) so you can't be really precise on the events if you don't want to manage bounding box yourself.
Or you can just use ImageButton for the tabs with a label in front for the text, it would be way easier but less flexible (tabs should all be the same sizes).

WPF expander troubles

I used many expander in the WPF application.. but I face some troubles:
When I try to put them below each others, the upper one expands automatically and makes it difficult to put the net one below it.. So I should separate the upper one in any place until I put the lower one then move back the upper one again. Can I keep expander unexpanded to make it easy to put any controls below it?
When I press ctrl+f5 and expand one of them, I see it has a transparent background and makes interruption with the lower ones - how can I avoid that?
I used scroll bar inside expander, but it doesn't work when i press ctrl+f5. I have an inactive scroll bar. How can I make link between scroll bar and expander to be able to move items inside expander up and down?
This is a picture to explain what I mean.
have a look at ths tutorial, it covers stuff like this, The Expander can be a tricky control to deal with sometimes, but once you understand the the expanders layout it becomes a bit easier.
http://blogs.msdn.com/b/wpfsldesigner/archive/2010/02/03/taming-the-wpf-expander-control.aspx

Dynamic layout of WPF controls which depends on some condition

I'm using WPF and I have a problem with layouting. I have got a docked panel (non WPF, I just hosted my control inside). And when a user wishes to dock this panel on the left or the right of the screen, I need to layout my controls in one way. But when the user wishes dock this panel on top or bottom, I need to layout my controls in another way.
My question is what is the best way to implement dynamic layout of WPF controls, which depends on some conditions?
I understand, that I can use the grid and dynamically change positions of my controls inside the grid. But I am not really happy with this solution. I'm looking for a solution with no code intervention, xaml only. And in case this is impossible, at least involving minimum intervention in the code.
Thanks in advance.
You could use AvalonDock to get a docking system very much like visual studio's.
This would give your users full control on the layout they desire, and it's not too hard to implement.
But if you really want a quick way to do this, I'd recommand Binding the DockPanel.Dock property to a ViewModel value that changes upon user input (along with an IValueConverter if necessary).
For this purposes DataTemplate feature is.
The idea is to provide multiple DataTemplates and then using your custom inplementation of the DataTemplateSelector rturn right DataTemplate based on criteria.
For an example see my post regarding DataTemplates
Data Templating Overview
Use StoryBoard and change the transformation of controls

Show and Hide UserControls (BringToFront/SendToBack)

I'm working on a "tricky" UI. Part of what I need to do is easily show and hide various UserControls. Generally one control will occupy the entire main window when needed, the other's will hide.
In WinForms I used to simply use SendToBack and BringToFront and easily showed the control I wanted to show. Now I have no clue. Played around with zorder but that didn't seem to work.
I'm thinking maybe put all the controls I want on the main window, then pro-grammatically resize them and remove the unused ones... or something.
Any ideas?
You should set the Visibility property to Collapsed, Hidden or Visbible depending on whether you want the controls removed, hidden or shown.
As #AresAvatar points out Collapsed removes the control completely so it takes up no space, this means that other controls may move around the container. If the position of elements is important then using Hidden will be the better option.
UIElement.Visibility Property on MSDN
Visibility Enumeration on MSDN

How to reuse WPF ScrollViewer to create my own scrollable control?

I'm trying to improve the graph drawing control that comes with Graph#. It's good, but things get out of hand when you start dragging nodes around. This is my first encounter with WPF, so this is probably a newbie question. :)
I have the GraphCanvas control which has nodes and edges on it. They can be dragged around which changes their coordinates, possibly making them negative. I would like to add scrollbars to the control which would allow to see how big the canvas really is.
To this end I'm thinking of putting the GraphCanvas inside a ScrollViewer. Which would be pretty easy and straightforward if not for one problem. I may not resize the GraphCanvas itself when a node is dragged outside the borders or this will mess up dragging bad. That is also the problem with the original control (check it out, it comes with a sample application).
It would be good if I could bind the scrollbar size/location to properties of the GraphCanvas, so that the ScrollViewer would not scroll anything physically, but just set the properties of GraphCanvas. That in turn would perform all actual calculations and scrolling.
How can this be done?
OK, I found it! Three easy steps:
Implement System.Windows.Controls.Primitives.IScrollInfo on your custom control;
Add your custom control to a ScrollViewer;
Set the CanContentScroll property on the ScrollViewer to True.
Voila!
Check out this link straight from MSDN. It talks about composing several controls into a single Composite Control:
WPF: Customizing Controls for Windows Presentation Foundation

Categories