iconPacks with MouseLeftButtonDown throws an exception

0
<UserControl x:Class="XXX.Apps.UI.Wpf.UserControls.AccountTile"
             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:local="clr-namespace:XXX.Apps.UI.Wpf.UserControls"
             xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             mc:Ignorable="d">

...

<iconPacks:PackIconModern Grid.Column="1" Grid.Row="1" Height="12" Kind="Delete" MouseLeftButtonDown="deleteIcon_Click" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" />

gives me

Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll

Additional information: 'Set connectionId threw an exception.' Line number '8' and line position '14'.

Inner:

Could not load file or assembly 'MahApps.Metro.IconPacks, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

... only when I have the MouseLeftButtonDown attribute on the icon.

Obviously my own assembly is signed. I have added the 'MahApps.Metro.IconPacks' as NuGet package. Don't tell me you didn't sign your assembly?

How to solve this? Thanks.

mahapps.metro
asked on Stack Overflow Dec 20, 2016 by hyankov • edited Dec 20, 2016 by hyankov

1 Answer

0

Since the icon pack is not strong signed, you could try using it like this:

<Button Content="{iconPacks:PackIconModern Delete, Width=12, Height=12}" Width="12" Height="12" Style="{StaticResource IconButtonStyle}" Click="deleteIcon_Click" />

And here's the style:

<Style x:Key="IconButtonStyle" TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid Background="Transparent" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Output

Output

Please note that if you set width and height, clicking outside the icon will not fire the event

answered on Stack Overflow Jan 10, 2017 by appa yip yip

User contributions licensed under CC BY-SA 3.0