2
votes

In my Prism 6 WPF MVVM application I use the following PrismUserControl WPF for displaying of modal notification dialogs:

<UserControl x:Class="CommonWpfControlLibrary.NotificationDialogPopupView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
         xmlns:prism="http://prismlibrary.com/"             
         prism:ViewModelLocator.AutoWireViewModel="True"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" MaxHeight="300" MaxWidth="600">

    <StackPanel Orientation="Vertical" Margin="20">
        <TextBlock Text="{Binding Message}" TextWrapping="Wrap"/>
        <telerik:RadButton Content="OK" Command="{Binding OnOkPressedCommand}" HorizontalAlignment="Center" Width="50" Margin="0 10 0 0"/>
    </StackPanel>
</UserControl>

In the Views where I use this UserControl as a modal dialog content I define it as following:

<i:Interaction.Triggers>
    <prism:InteractionRequestTrigger SourceObject="{Binding NotificationRequest, Mode=OneWay}">
        <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
            <prism:PopupWindowAction.WindowContent>
                <commonControls:NotificationDialogPopupView/>
            </prism:PopupWindowAction.WindowContent>
        </prism:PopupWindowAction>
    </prism:InteractionRequestTrigger>
</i:Interaction.Triggers>

When I activate the dialog it is displayed, for example, as the following: enter image description here

But as you can see 'Minimize', 'Maximize' and 'Close' buttons are visible and enabled. And the system menu (activated in upper left corner of the dialog) is enabled too. How can I hide 'Minimize', 'Maximize' and 'Close' buttons and disable the system menu?

5

5 Answers

2
votes

@Evangelink was close. You would use the WindowStyle property, but you must supply an actual Style. Something like:

<Style TargetType="{Window}">
     <Setter Property="" Value="" />
</Style>
1
votes

2.Disabling close buttons:

Not showing Icon and Close button: Unfortunately, this feature is not available in WPF. To achieve this, you can try setting the WS_EX_DLGMODALFRAME window style by calling [Get/Set]WindowLong (pInvoking in to Win32) from the SourceInitialized event on the Window class. Check this:

public partial class MainWindow : Window
{

[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);



const uint MF_BYCOMMAND = 0x00000000;
const uint MF_GRAYED = 0x00000001;
const uint MF_ENABLED = 0x00000000;

const uint SC_CLOSE = 0xF060;

const int WM_SHOWWINDOW = 0x00000018;
const int WM_CLOSE = 0x10;

public MainWindow()
{
    InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{

}

protected override void OnSourceInitialized(EventArgs e)
{
    base.OnSourceInitialized(e);

    HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;

    if (hwndSource != null)
    {
        hwndSource.AddHook(new HwndSourceHook(this.hwndSourceHook));
    }
}


IntPtr hwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == WM_SHOWWINDOW)
    {
        IntPtr hMenu = GetSystemMenu(hwnd, false);
        if (hMenu != IntPtr.Zero)
        {
            EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
        }
    }
    else if (msg == WM_CLOSE)
    {
        handled = true;
    }
    return IntPtr.Zero;
  }
}
0
votes

I don't have any working example right now so I might have an uncomplete answer.

By looking to Prism source code PopupWindowAction I can see a WindowStyle property that you can use to change the style of the popup. I guess the property value you are looking for is WindowStyle="ToolWindow".

Hope it helps!

0
votes

I found two solutioins :

1.Disable all windows property :

Set the Window.WindowStyle property to WindowStyle.None

2.Disabling buttons:

I. Disabling Minimize, Maximize buttons :
This can be achieved by setting Window.ResizeMode property to ResizeMode.NoResize. It will disable the minimize and maximize buttons. Furthermore, the window will not resize by mouse click+drag.

II. Not showing Icon and Close button:
Unfortunately, this feature is not available in WPF. To achieve this, you can try setting the WS_EX_DLGMODALFRAME window style by calling [Get/Set]WindowLong (pInvoking in to Win32) from the SourceInitialized event on the Window class.

0
votes

I have a workaround, if it suits your structure. Expose a Usercontrol loaded event in code behind (can be achieved also using MVVM) of your Usercontrol NotificationDialogPopupView

Loaded="UserControl_Loaded"

and write down following code in the Loaded event

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Window win = ((UserControl)sender).Parent as Window;
            if(win != null)
            {
                win.WindowStyle = WindowStyle.None;
                win.ResizeMode = ResizeMode.NoResize;

            }
        }