Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide 'Minimize', 'Maximize' and 'Close' buttons from PrismUserControl WPF?

Tags:

c#

mvvm

wpf

prism

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?

like image 322
Prohor Avatar asked Sep 03 '25 04:09

Prohor


2 Answers

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.

like image 101
Yiao SUN Avatar answered Sep 04 '25 18:09

Yiao SUN


@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>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!