3

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?

<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>
H.B.
  • 166,899
  • 29
  • 327
  • 400
Shazter
  • 305
  • 1
  • 4
  • 17
  • 1
    Solved by code behind as explained here: http://stackoverflow.com/questions/5971300/programmatically-changing-button-icon-in-wpf – Shazter Aug 16 '16 at 14:39

1 Answers1

2

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

PackIcon packIcon = new PackIcon();
packIcon.Kind = PackIconKind.FullscreenExit;
btnResizeDashboard.Content = packIcon;
GGamba
  • 13,140
  • 3
  • 38
  • 47
HKNBKN
  • 21
  • 4