Drag-and-drop widget is not not working for Win32 applicaiton in administrative mode
Shyam Butani
240
Reputation points
Hello,
I'm creating Win32 application with XAML island. I want to allow drag-and-drop of UI element. Below is the code to give an idea of what I'm trying to do. Basically, I want to drag TextBlock and drop on Canvas.
This is working as expected for normal launch, but if I launch in administrative mode, it's crashing when I try to drag the TextBlock.
Can you please help me understand the reason and possible fix to this issue?
TextBlock* tb1, * tb2;
Canvas* z1;
StackPanel* xc;
void DragStarting([[maybe_unused]] UIElement const& pSender, DragStartingEventArgs const& pArgs) noexcept
{
pArgs.Data().SetText(pSender.try_as<FrameworkElement>().Name());
}
void DragOver(const winrt::Windows::Foundation::IInspectable pSender, DragEventArgs const& pArgs) noexcept
{
pArgs.AcceptedOperation(DataPackageOperation::Move);
}
void Drop(const winrt::Windows::Foundation::IInspectable pSender, DragEventArgs const& pArgs) noexcept
{
uint32_t index;
if (pArgs.DataView().Contains(StandardDataFormats::Text())) {
if ((*xc).Children().IndexOf(*tb1, index)) {
(*xc).Children().RemoveAt(index);
(*z1).Children().Append(*tb1);
}
}
}
int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
// ... create window and xaml island ...
// Add UI elements for drag and drop
Windows::UI::Xaml::Controls::StackPanel xamlContainer;
Canvas zone;
Windows::UI::Xaml::Controls::TextBlock textblock;
Windows::UI::Xaml::Controls::TextBlock textblock1;
tb1 = &textblock;
tb2 = &textblock1;
z1 = &zone;
xc = &xamlContainer;
textblock.Text(L"Drag this...");
textblock.Name(L"textblock");
textblock.CanDrag(true);
textblock.DragStarting(DragStarting);
xamlContainer.Children().Append(textblock);
textblock1.Text(L"Drop here...");
textblock.Name(L"textblock1");
zone.Children().Append(textblock1);
zone.Margin({ 100, 100, 100, 100 });
zone.AllowDrop(true);
zone.DragOver(DragOver);
zone.Drop(Drop);
xamlContainer.Children().Append(zone);
// ... Message loop ...
return 0;
}
Thanks.
Sign in to answer