I have just start working with Microsoft Surface.I have designed a UserControl in Blend 4. And implemented a simple DrapDrop event over the UserControl. It works fine. The problem is, when i click over the UserControl, UserControl just jumps to another location.
For dragdrop, i have use this code
How to drag a UserControl inside a Canvas
The only design difference is, my UserControl is inside the Grid. And in this example, it is implemented inside a Canvas.
To move things around the screen on Surface, you want to use the ScatterView control.
Related
I'm trying to host a dx12 viewport in WPF, but it seems I can only render to the full window.
I've tried to set D3D12VIEWPORT.Width to half of the window's width, and i got this
And I've tried to set the width of the ScissorRect to half of the window, then I got this.
Is there a way to draw to only part of the window and left the rest part of window for UI?
I think I found a solution.
Just in case anyone runs into the same problem when trying to make WPF and dx work together:
1.Add a WindowsFormsControlLibrary project to the solution.
2.Handles the message in a winform usercontrol by overriding WndProc.
3.Embed the winform usercontrol into WPF main window.
4.Render into the embedded winform usercontrol.
I have a window with a popup that pops when an item in a listview is double clicked.
It centers to the main window and looks really nice floating there.
The problem is when the user moves the main window or selects another program, and the popup floats on top of other stuff.
I would like to have something like a popup, meaning that it floats on top of other elements in the window, but sticks with the main window when it moves (stays centered), and doesn't float on top of other programs.
Can I make a popup act like this, or is there a better way to do it?
Popups will not move while the window is resized or moved. Because, Popups/Context menus are not the part of Visual Tree. You have to use Adorner for this. I will suggest to read this four part series for a quick start on Adorner.
It's possible that an Adorner will fit your needs in this case better than a popup. Adorners can float above your window, too. There are a few differences, mainly that an adorner is bound to a UIElement (which include windows).
If you are willing to use a third-party/open source (MS-PL) option, the Extended WPF Toolkit has a ChildWindow control.
It's technically not a separate window, but it appears to be a separate window to the user.
I have not found a way to make Popups stop doing that in WPF
As an alternative, you can create a UserControl which acts like a Popup.
Usually I host the content section of the app along with the Popup within a Canvas control, and when IsPopupOpen gets changed to True I set the popup Visibility = Visible.
I want to create custom WPF control that has a single "child" control inside. Subclassing ContentControl or UserControl works, but has one flaw: these controls don't work in designer mode.
By "don't work" I mean this scenario: suppose I have a Canvas with my custom control in it. I want to put, say, a Button inside my control. I drag it from the toolbox, and it appears inside my control. However, XAML view shows that the new button actually belongs to Canvas, not to my control.
I can place it inside my control by manually editing XAML, but I want the designer to work too.
Interestingly, when I subclass Canvas, Grid or Panel, designer works as expected. However, these controls have many children, which is not what I need.
How can I make a single-child control that works in designer?
how about inheriting from Border? that way you could spare yourself the hassle with Designer Extensibility
I had the same problem with a content control I am writing and found an easy solution on this
StackOverflow thread.
Just implement the HitTestCore method:
protected override System.Windows.Media.HitTestResult HitTestCore(System.Windows.Media.PointHitTestParameters hitTestParameters)
{
return new PointHitTestResult(this, hitTestParameters.HitPoint);
}
I also had a similar question here.
But after digging and digging it seams that the real answer is "NO", there isn't any official way to support dragging controls straight into a custom Content-Control at Design-Time, even implementing 'HitTestCore' as Stephan's answer suggests, does not enable drag&drop at design-time for ContentControl.
For such purposes you should consider inheriting from either Grid or Panel (to allow multiple child controls), or Border (to allow single child).
I am working with a WPF application that uses alot of drag and drop. Everything is working fine, with exception of ListBoxItems. I have a ListBox with ListBoxItems that can be dragged to another target( a StackPanel). The problem is, when I drag the cursor outside the ListBox, I cant see the Adorner that I have setup with the ListBoxItem?
I know this is a common problem, but I am just not sure how to fix it. Is there something that I need to do to allow me to drag outside of the ListBox control?
Below I have attached what the UI looks like so far. As you can see, there is a ListBox on the bottom left. When I drag an item, the adorner appears, and follows the cursor around while the cursor is over the ListBox, but if I try to move the cursor away from the listbox, the Adorner seems to almost go under the other controls(zIndex?).
Edit - Solution
I have changed the code to handle the AdornerLayer relative to the window as oppose to relative to the AdornedElement
So I changed
layer = AdornerLayer.GetAdornerLayer(_originalElement);
to
layer = AdornerLayer.GetAdornerLayer(this);
This solved the problem of the ScrollViwer clipping the AdornerLayer
The ListBox (or, to be specific, the ScrollViewer within the listbox) clips any adorners attached to it's children. This is done to ensure that adorners for items scrolled out of view are not shown. To get around this, you need to explicitly put thing in the Window's adorner and not that of the listbox or listboxitem
I just added a ScrollViewer to my WPF app. Now some of my content is hidden because it is at the bottom of the ScrollViewer--this is intentional. However, is there any way in the Design view of Visual Studio 2010 to scroll a scrollbar so that I can preview what my app looks like when the scrollbar is at different positions? It would be convenient to check this out without having to build my Solution and run my app, just to scroll down and make sure things look as I expect.
My ScrollViewer is contained in a UserControl that does not have a height set on it. I set my ScrollViewer's height to Auto so all the contents of the ScrollViewer show in Design view in my UserControl--this way, I can see what I'm doing. I set the height of the Window that includes the UserControl, so when I run my app the ScrollViewer is bounded by that Window height, as desired.
I just removed these properties from my UserControl in Visual Studio.
d:DesignHeight and d:DesignWidth
Like yours, my ScrollViewer's height was already set to Auto.