oleg-shilo / wixsharp

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

Can use Resource Dictionary? #1499

Closed grizoood closed 2 months ago

grizoood commented 2 months ago

Can we use a Resource Dictionary for styles, datatemplates, etc.?

I try style RoundButton but the msi not show, not start :

image

<wixsharp:WpfDialog
    x:Class="WixSharp_Setup1_WPF_UI.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"
    d:DesignHeight="408"
    d:DesignWidth="512"
    DialogTitle="[ProductName] Setup"
    mc:Ignorable="d">
    <wixsharp:WpfDialog.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Assets/ResourceDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </wixsharp:WpfDialog.Resources>
  <Button
      x:Name="GoPrev"
      Height="23"
      MinWidth="73"
      Style="{DynamicResource RoundButton}" Background="White">
      [WixUIBack]
  </Button>
</wixsharp:WpfDialog>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style TargetType="Button" x:Key="RoundButton">
        <Style.Resources>
            <Style TargetType="Border">
                <Setter Property="CornerRadius" Value="5" />
            </Style>
        </Style.Resources>
    </Style>

</ResourceDictionary>
oleg-shilo commented 2 months ago

You can. But as you might be aware WPF runtime is very sensitive on the assembly hosting model when it comes to loading the resource dictionaries. Thus Source="/Assets/ResourceDictionary.xaml" needs to be a fully qualified resource uri, which includes the assembly name (I think).

it is a little black magic... The URI can be:

You will need to play around that URI

grizoood commented 2 months ago

I allow myself to reopen because my msi still does not open, I see the first interface with the progressbar but I never see the home page.

When I delete the dictionary it works, it shows me the welcome page.

grizoood commented 2 months ago

Yes, the second method works:

<wixsharp:WpfDialog.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!--<ResourceDictionary Source="/Assets/ResourceDictionary.xaml" />-->
            <ResourceDictionary Source="pack://application:,,,/WixSharpSetupWPFUI;component/Assets/ResourceDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</wixsharp:WpfDialog.Resources>
oleg-shilo commented 2 months ago

Great. Thank you for sharing. You've done it very quickly. Sometimes it can take much longer to find the right syntax...