材料设计风格的PackIcon套件

3

我使用Material Design创建了一个用户控件按钮,基于其方法,我想通过更改图标来重用模板。我尝试将materialdesign:Packicon添加到UserControl.Resources中,但似乎有错。属性Style已经在使用中了。我该如何实现图标的更改?

<UserControl x:Class="MaterialDesignTest1.UserControl2"
             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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             mc:Ignorable="d" d:DesignWidth="300" Height="132">
    <UserControl.Resources>
            <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </UserControl.Resources>
<Grid>
<Grid Height="132" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />

                </Grid.RowDefinitions>
              <!-- Header -->
                <Button Grid.Row="0" Grid.Column="0" Background="WhiteSmoke" BorderBrush="LightGray" Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" 
                        HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1,1,1,1" Width="50" Height="50">
                    <materialDesign:PackIcon Height="30" Width="30" Kind="BluetoothConnect" />
                </Button>

</Grid>

1
通过代码后台解决,如此所述:https://dev59.com/D2025IYBdhLWcg3wfmLw - Shazter
1个回答

2
在代码后台,创建一个新的PackIcon,将按钮的内容设置如下:
PackIcon packIcon = new PackIcon();
packIcon.Kind = PackIconKind.FullscreenExit;
btnResizeDashboard.Content = packIcon;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接