question

AndreasMazatis-6476 avatar image
0 Votes"
AndreasMazatis-6476 asked JackJJun-MSFT edited

WinUI - Real DialogWindow

I need a real pop-up in my WinUI application. A ContentDialog is not a solution because the window must be movable. Then I played with PINVOIKE and found a semi-solution. Unfortunately there are the following problems :

  • With a double click on the caption bar the window is maximised

  • The window size can be changed

  • The Close button is old style.



Does anyone know a solution for these problems?

Here ist my Coding:
var dpi = GetDpiForWindow(iHwnd);
float scalingFactor = (float)dpi / 96;
iLeft = (int)(iLeft scalingFactor);
iTop = (int)(iTop
scalingFactor);
iHeight = (int)(iHeight * scalingFactor);
= SetWindowPos(iHwnd,
SpecialWindowHandles.HWND_TOPMOST, // --- Stay on Top
iLeft, iTop, iWidth, iHeight, // --- Koordinates
SetWindowPosFlags.SWP_NOMOVE);
= SetWindowLong(iHwnd, WindowLongIndexFlags.GWL_EXSTYLE, SetWindowLongFlags.WS_EX_TOOLWINDOW);

dotnet-csharpwindows-app-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered

I need a real pop-up in my WinUI application. A ContentDialog is not a solution because the window must be movable.

You can move a ContentDialog with UIElement.ManipulationMode

A test =>

         private async void ShowDialog()
         {
             StackPanel sp = new StackPanel();
             FontIcon fi = new FontIcon()
             {
                 FontFamily = new FontFamily("Segoe UI Emoji"),
                 Glyph = "\U0001F439",
                 FontSize = 50
             };
             sp.Children.Add(fi);
             TextBlock tb = new TextBlock();
             tb.HorizontalAlignment = HorizontalAlignment.Center;
             tb.Text = "Test ContentDialog";
             sp.Children.Add(tb);
             ContentDialog cd = new ContentDialog()
             {
                 Title = "Information",
                 Content = sp,
                 CloseButtonText = "Ok",
                 ManipulationMode = ManipulationModes.All
    
             };
             cd.ManipulationDelta += delegate (object sender, ManipulationDeltaRoutedEventArgs e)
             {
                 if (!e.IsInertial)
                     cd.Margin = new Thickness(
                         cd.Margin.Left + e.Delta.Translation.X,
                         cd.Margin.Top + e.Delta.Translation.Y,
                         cd.Margin.Left - e.Delta.Translation.X,
                         cd.Margin.Top - e.Delta.Translation.Y
                         );
             };
             cd.XamlRoot = this.Content.XamlRoot;
             var res = await cd.ShowAsync();           
         }


201621-contentdialog-movable.gif




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.