带有 MouseLeftButtonDown 的 iconPacks 抛出异常
iconPacks with MouseLeftButtonDown throws an exception
<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" />
给我
Exception thrown: 'System.Windows.Markup.XamlParseException' in
PresentationFramework.dll
Additional information: 'Set connectionId threw an exception.' Line
number '8' and line position '14'.
内部:
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)
...仅当我在图标上具有 MouseLeftButtonDown
属性时。
显然我自己的程序集已签名。我已将 'MahApps.Metro.IconPacks' 添加为 NuGet 包。别告诉我你没有在大会上签名?
如何解决这个问题?谢谢。
由于图标包不是强签名的,您可以尝试这样使用它:
<Button Content="{iconPacks:PackIconModern Delete, Width=12, Height=12}" Width="12" Height="12" Style="{StaticResource IconButtonStyle}" Click="deleteIcon_Click" />
样式如下:
<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>
输出
请注意,如果您设置了宽度和高度,则在图标外点击不会触发事件
<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" />
给我
Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll
Additional information: 'Set connectionId threw an exception.' Line number '8' and line position '14'.
内部:
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)
...仅当我在图标上具有 MouseLeftButtonDown
属性时。
显然我自己的程序集已签名。我已将 'MahApps.Metro.IconPacks' 添加为 NuGet 包。别告诉我你没有在大会上签名?
如何解决这个问题?谢谢。
由于图标包不是强签名的,您可以尝试这样使用它:
<Button Content="{iconPacks:PackIconModern Delete, Width=12, Height=12}" Width="12" Height="12" Style="{StaticResource IconButtonStyle}" Click="deleteIcon_Click" />
样式如下:
<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>
输出
请注意,如果您设置了宽度和高度,则在图标外点击不会触发事件