【问题标题】:Material Design Style PackIcon材料设计风格 PackIcon
【发布时间】:2016-08-16 12:19:31
【问题描述】:

我使用 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>

【问题讨论】:

标签: c# wpf


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 2014-12-16
    • 1970-01-01
    • 2021-06-24
    • 2019-01-29
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多