wpf Material Design Style PackIcon

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38974803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:54:38  来源:igfitidea点击:

Material Design Style PackIcon

c#wpf

提问by Shazter

I created with Material Design a UserControl Button, based on the method behind I would like to reuse the template with change of the icon. I tried to add the materialdesign:Packicon into the UserControl.Resources, but seems wrong. The Attribute Style is already in use. How can I achieve my icon change?

我使用 Material Design 创建了一个 UserControl 按钮,基于后面的方法,我想通过更改图标来重用模板。我试图将 materialdesign:Packicon 添加到 UserControl.Resources 中,但似乎是错误的。属性样式已在使用中。如何实现我的图标更改?

<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>

回答by HKNBKN

in code behind, create a new packicon, set the content of the button like below:

在后面的代码中,创建一个新的packicon,设置按钮的内容如下:

PackIcon packIcon = new PackIcon();
packIcon.Kind = PackIconKind.FullscreenExit;
btnResizeDashboard.Content = packIcon;