I see some QnAs in our SO discussing about how to detect a drag-n-drop event but sometimes, for some reason such as application A run with admin right whist application B did not, the drag-n-drop is NOT allowed by Windows OS.
My question is: How can we detect a NOT-possible drag-n-drop happens in our code?
Edit
This question is about drag-n-dropping between two applications, one is privileged (run as admin) and other is NOT. Dragging between them is not allowed by Windows OS. I want to detect that situation and pop up a message in my application to let the users know why dragging then is not possible.
I guess you can do this using the DragOver event
private void UserControl_DragOver(object sender, DragEventArgs e)
{
//Verify that this is a valid drop
if (!Validate())
{
e.Effects = DragDropEffects.None;
e.Handled = true;
}
}
Related
I have a Desktop Application written in WPF (originally for Windows 7) that I would like to run in Kiosk (Assign Access mode) on a Microsoft Surface Pro 2. The assigned access feature looked perfect, but it doesn't support non-store apps.
I just need a way to prevent the user from switching to another app or getting access to the OS etc.
Possible?
Make your application fullscreen as shown here: full screen wpf
In your main window constructor subscribe on Deactivate event or override OnDeactivate method:
Deactivated += delegate(object sender, EventArgs e) {
Activate();
};
You would also want to prevent the window from Alt+F4 closing by handling the Closing event on such a way:
Closing += delegate(object sender, CancelEventArgs e)
{
if(!Environment.HasShutdownStarted)
e.Cancel = true;
};
After all done, the application is closable only by task manager, sign out and shutdown.
I'm trying to put together a small application in WPF (a media player) using Visual Studio 2012 Express for Desktop, and want to use the space bar to pause. Unfortunately, the space bar, as well as the enter key, seem to have a default behavior in which (just before they execute any commands I have programmed for them) they re-execute or re-raise the most recent event in the window (button clicks, keypresses, etc.).
I have tried overriding OnKeydown, OnKeyUp, OnPreviewKeyDown, and OnPreviewKeyUp in every combination, but no amount of overriding eliminates this behavior. I have also found that this is true in other WPF applications I wrote, and even in a Windows Forms application I put together a few months ago. Is this some default aspect of all applications built by Visual Studio? And more importantly, is there a way to get rid of it?
If you override OnPreviewKeyDown you can add the logic you want, then set e.Handled to true and this will prevent the event from bubbling up and causing the behavior you are seeing.
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter || e.Key == Key.Space)
{
//Your Logic
e.Handled = true;
}
}
I created a Border on a WPF User Control and signed up for the Touch Down and the Mouse Left Button Down Event.
<Border
TouchDown="Border_TouchDown_1"
MouseLeftButtonDown="Border_MouseLeftButtonDown_1">
<Label FontSize="28">Label</Label>
</Border>
In the code behind file I have following event handlers:
private void Border_TouchDown_1(object sender, TouchEventArgs e)
{
e.Handled = true;
Result.Append("Border_TouchDown_1" + "\n");
LogText = Result.ToString();
RaisePropertyChange();
}
private void Border_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
{
Result.Append("Border_MouseLeftButtonDown_1" + "\n");
LogText = Result.ToString();
RaisePropertyChange();
}
On a Touch Gesture in windows 8 I see both event handlers getting triggered even if the event is handled in the Border_TouchDown_1 method.
In Windows 7 I see only the Border_TouchDown_1 method gets called which seemed to be correct because the event is handled.
I guess Microsoft concisely decided to fire both events to make all Applications Touch aware which is ok for Mouse only application but my application is Touch aware and I would like to switch this behavior off.
Anybody with some insides out there???
Do you know what will blow your mind? If you DO NOT set e.Handled = true, you won't get the mouse event (at least for PreviewTouchDown / PreviewMouseDown). It's almost like someone made a typo for windows 8 and it is working backwards.
I have a WPF 4 application where I have implemented Drag and Drop using the standard DragDrop.DoDragDrop approach, but Im doing it using touch instead of Mouse events.
My XAML for my Grid (that Im dragging) is as follows:
<Grid x:Name="LayoutRoot"
ManipulationStarting="ManipulationStarting"
ManipulationDelta="ManipulationDelta"
ManipulationCompleted="ManipulationCompleted"
IsManipulationEnabled="True">
<!-- children in here -->
</Grid>
Now the code behind is like this:
private void ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = this;
e.Handled = true;
}
private void ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
e.Handled = true;
DragDrop.DoDragDrop(this, new DataObject(GetType(), this), DragDropEffects.Move);
}
private void ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
//completed stuff
}
BUT when I try to drag with one finger while already dragging with another finger (different hands for example, which would simulate two people) the second touches don't seem to register properly, infact, it seems that windows thinks that my two fingers are trying to scale (like a pinch gesture)...
Does anyone know a way to get around this?
Thanks a lot
Mark
For multi-touch, you're going to want to use the Surface Toolkit for Windows Touch. It includes a drag-and-drop framework suitable for multi-touch scenarios. It includes a drag-and-drop framework. That link includes several how-to scenarios.
Although this is just an educated guess, I would say that DragDrop.DoDragDrop() is not capable to handle multiple drag guestures in parallel.
Indices:
There's no possibility to pass a touch ID to the method (which would be neccessary for differentiating the ongoing drag gestures)
The implementation of DoDragDrop() is static
The call of DoDragDrop() is blocking until the drop occured or was canceled
It is based upon the OLE version of drag and drop (which was not updated for Win7)
However, I would be glad if someone could correct me in this matter, because I'm currently also searching an DND API suitable for touch support.
Regards,
Seven
I have a problem.
I am calling an external application(web) through a WPF WebBrowser Control. The
application is opening properly. Now in the web application, there are certain hyperelinks.
If a user click on that hyperlink, I should be able to trap it's value.
How to achieve the same using this WEB BROWSER.. I mean, in which event , what code I need to write to get it work
Using C#3.0, WPF and Dotnet framework 3.5
Thanks
Try this.
private void _webBrowser_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (string.IsNullOrEmpty(e.Uri.AbsolutePath))
{
e.Cancel = true;
string actionName = e.Uri.LocalPath;
MessageBox.Show(actionName);
}
}
Regards,
Nanda