oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.08k stars 172 forks source link

Custom Behavior for "X" button in the title bar #1573

Closed Aaswin1996 closed 2 weeks ago

Aaswin1996 commented 2 months ago

I am creating an installer using the WPF UI examples.I need to handle the behavior whenever any user clicks on the "X" button in the installer title bar .

image

How to handle that without using the External UI .I am using caliburn .

xaml code :


    x:Class="ScoutWpfInstaller.WelcomeDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:wixsharp="clr-namespace:WixSharp.UI.WPF;assembly=WixSharp.UI.WPF"
    xmlns:WinUi3="http://schemas.lepo.co/wpfui/2022/xaml"
    FontFamily="Inter"
    Padding="20"
    Background="White"
    DialogTitle="Scout Setup" 

    >
    <wixsharp:WpfDialog.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <WinUi3:ThemesDictionary Theme="Light" />
                <WinUi3:ControlsDictionary />
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="BoolToVis" />
        </ResourceDictionary>
    </wixsharp:WpfDialog.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!-- left pane -->

        <!-- right pane -->
        <Grid Grid.Column="1" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions >
                <RowDefinition Height="*" />
                <RowDefinition Height="30" />
                <RowDefinition Height="50" />
            </Grid.RowDefinitions>

            <!-- content -->
            <Grid Grid.Row="0" >

                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="40" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="160" />
                    <RowDefinition Height="10" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <TextBlock x:Name ="WelcomeDialogTitle" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
                    Add Scout Icon Here
                </TextBlock>
                <TextBlock Grid.Row="3" x:Name="DialogDescription" HorizontalAlignment="Center" VerticalAlignment="Center">
                    Getting Scout ready for you 
                </TextBlock>
                <WinUi3:ProgressRing Name ="Prgring" Grid.Row="6"  IsIndeterminate="true" Visibility="{Binding ProgressSpinner, Converter={StaticResource BoolToVis}}" ></WinUi3:ProgressRing>
                <TextBlock Grid.Row="8" HorizontalAlignment="Center" VerticalAlignment="Center">
                    Checking System Requirements
                </TextBlock>
            </Grid>

        </Grid>

    </Grid>
</wixsharp:WpfDialog>```
oleg-shilo commented 2 months ago

In your dialog init:

public partial class WelcomeDialog : WpfDialog, IWpfDialog
{
    public WelcomeDialog()
    {
        InitializeComponent();
    }

    public void Init()
    {
        var topWindow = this.ManagedFormHost.Parent as System.Windows.Forms.Form;
        topWindow.FormClosing += (sender, e) =>
        {
            MessageBox.Show("Closing...");
        };

        ViewModelBinder.Bind(new CustomDialogModel { Host = ManagedFormHost }, this, null);
    }
Aaswin1996 commented 1 month ago

@oleg-shilo Thanks for the reply ...Can we style the title bar I basically want to make the edges rounded ...I am using a managed WPF installer . PS : thanks for WixSharp it has made my life a hell lot easier

oleg-shilo commented 1 month ago

thanks for WixSharp it has made my life a hell lot easier

Great to hear. Appreciate it.

Can we style the title bar I want to make the edges rounded Sorry, this is beyond WixSharp responsibilities. WixSharp provides the standard (stock) appearance and behaviour. Just to meet the major user base expectations. Anything more will be specific to the user and must be implemented by the user.

Rounded edges are not simple to implement when dealing with Windows Forms. Yes, even when you use WPF your top-level window is still a System.Windows.Forms.Form instance.

Thus I suggest you look at the External_UI sample which will give you complete freedom of WPF implementation of all visual elements.

image