Reputation: 2792
I am adding storage items to DataPackage when UIElement drag starts, but the problem is if I drag it to other apps or to Windows desktop, Windows interferes with drop action. Is there any way I can restrict the DataPackage to be only read by my app??
Upvotes: 1
Views: 333
Reputation: 7727
In UWP, you can write data to DragItemsStartingEventArgs.Data
in the DragItemsStarting
event. You are writing StorageItem
. When dragging to the desktop, the system will call the corresponding default processing method. This behavior is a system behavior, and the UWP application cannot prevent it.
If your purpose is just to drag the tab and create a new window, you don’t need to write data to DataPackage
, just let it be processed inside the application, and listen to the DragItemsCompleted
event.
private void Tabs_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
//get file
e.Items.Add(myFile);
}
private void Tabs_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
{
var items = args.Items;
if (items.Count > 0)
{
foreach (var item in items)
{
if(item is StorageFile file)
{
// create new window
}
}
}
}
If the data is written to DataPackage
, it means that the party that obtains the data processes the data (such as a desktop or other software), and this process application cannot interfere.
Thanks.
Upvotes: 1