3

We use own styled image buttons. On our developer computer (all Win 7 x64 VS 2013) works all well. Also on customer computers with Win7 x64 .Net 4.5.x.

On the test computer with Win 7 x32 .Net 4.0 the image buttons have the standard style of the button, not the new style. On Win 7 x32 with .Net 4.5 it works. So I think the problem is in the .Net version rather than x32 Architecture.

Our style for the image buttons

<!-- Default Template -->
<Style TargetType="{x:Type con:PreparedImageButton}" BasedOn="{x:Null}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type con:PreparedImageButton}">
                <Border
                    x:Name="_PART_BORDER"
                    CornerRadius="0"
                    BorderThickness="0"
                    Width="{TemplateBinding Width}"
                    Height="{TemplateBinding Height}"
                    Padding="{TemplateBinding Padding}"

                    Background="{DynamicResource DefaultBackground}">
                    <Viewbox Stretch="Uniform">
                        <ContentPresenter x:Name="_PART_SIGN" Content="{x:Null}" />
                    </Viewbox>
                </Border>
                <ControlTemplate.Triggers>
                    <!-- Background Trigger -->
                    <!-- Disabled Background -->
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="_PART_BORDER" Property="Background"
                                Value="{DynamicResource DisabledBackground}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="True">
                        <Setter Property="Cursor" Value="Hand" />
                    </Trigger>
                    <!-- Pushed Background -->
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="_PART_BORDER" Property="Background"
                                Value="{DynamicResource PushedBackground}" />
                    </Trigger>

                    <!-- Button Type Trigger -->
                    <!-- Next -->
                    <Trigger Property="ButtonType" Value="Next">
                        <Setter TargetName="_PART_SIGN" Property="Content" Value="{DynamicResource NextSignCanvas}" />
                    </Trigger>
                    <!-- Back -->
                    <Trigger Property="ButtonType" Value="Previous">
                        <Setter TargetName="_PART_SIGN" Property="Content" Value="{DynamicResource BackSignCanvas}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

In the most cases we use DataTemplate for our ViewModel

<!-- Default ViewModel Template -->
<DataTemplate DataType="{x:Type vm:PreparedImageButtonViewModel}">
    <con:PreparedImageButton ButtonType="{Binding ButtonType}"
                             IsVikingStyle="{Binding IsVikingStyle}"
                             Command="{Binding Command}"
                             IsEnabled="{Binding IsEnabled}"
                             Visibility="{Binding IsVisible, Converter={StaticResource BooleanVisibilityConverter}}"
                             IsCancel="{Binding IsCancel}"
                             IsDefault="{Binding IsDefault}"
                             ToolTip="{Binding ToolTip}"
                             Width="{DynamicResource DefaultButtonHeight}"
                             Padding="{DynamicResource DefaultSignPadding}"
                             Height="{DynamicResource DefaultButtonHeight}" />
</DataTemplate>

And in the Window / User controls we bind this buttons over ContentControl:

<ContentControl Content="{Binding ProtocolButton}" Margin="0,0,5,0" HorizontalAlignment="Right" />

Any idea what's going wrong with .Net 4.0?

Win7 x32 .Net 4.0 Windows 7 x32 .Net 4.0 Win7 x64 .Net 4.5 Windows 7 x64 .Net 4.5.1

Edit

It seems that .Net 4.0 is not able to resolve merged dictionaries correctly. Normally we merge external dictionaries in the Global.xaml of the current project.

If we do this with the image button, it doesn't work. If we merge the dictionary of the image button direct in the Windows/UserControl, where we use them, this works (under .Net 4.0).

For all other controls of us, merging works without problems.

We test now, if the problem is there, if we build the solution on the computer with only .Net 4.0 and VS2010.

WebDucer
  • 1,114
  • 2
  • 16
  • 39
  • first thing i would investigate is the version of the WPF assemblies like PresentationFramework & PresentationCore. I've done this before by running the app and then creating a dump using ProcessExplorer, the resultant dump can be openned in Visual studio and it should give you list of the loaded assemblies and importantly the full version of said assemblies. – AwkwardCoder Sep 25 '14 at 09:41
  • if they are different, ususally means the machines are patched to different dates, we had issues similar because some systems were missing certain MS hotfixes. – AwkwardCoder Sep 25 '14 at 09:44
  • It seems that .Net 4.0 (App build with VS2013 set on .Net 4.0) is not able to resolve merged dictionaries correct (see my edit). – WebDucer Sep 25 '14 at 10:07
  • from microsoft: To improve theme-level resource dictionaries and prevent them from changing, freezable resources that are defined in a resource dictionary and merged into a theme-level dictionary are now always marked as frozen and are immutable. This is the expected behavior for freezable resources. https://msdn.microsoft.com/en-us/library/ee941656(VS.100).aspx#windows_presentation_foundation_wpf – Idan Feb 26 '15 at 07:24

1 Answers1

0

the solution for me was as follows:

remove all of the resource dictionary's from the app.xaml and add them programmatically:

on the constructor of the App.xaml.cs

        var item = new ResourceDictionary
            {
                Source = new Uri("link to a skin for example")
            };
        Current.Resources.MergedDictionaries.Add(item);

        _appboot = new Bootstrapper();
        var bootRd = new ResourceDictionary {{"bootstrapper", _appboot}};
        Current.Resources.MergedDictionaries.Add(bootRd);

this should fix the problem.

the information about the issue can be found here: https://msdn.microsoft.com/en-us/library/ee941656(VS.100).aspx#windows_presentation_foundation_wpf

Idan
  • 509
  • 2
  • 10
  • 24