Search code examples
c#wpfxamlribbonfluent-ribbon

Set xaml icon in fluentribbon button


I use fluentribbon and mahapps for my GUI and want to have a button in my ribbon with a icon. I want to use xaml icons like this (not a file). So i need to set Path in the fluent:Button. I tried the following but its not working - Button is blank (no text and no icon shown):

<fluent:Button Name="Test">
    <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Center">
        <Path Width="40" Height="40" Stretch="Uniform" UseLayoutRounding="False" Fill="Black" Data="..."/>
        <TextBlock><Run Text="Test Button"/></TextBlock>
    </StackPanel>
</fluent:Button>

Update

Here is the complete code:

<Controls:MetroWindow  x:Class="RibbonTestProj.View.RibbonTest"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:fluent="urn:fluent-ribbon"
        Title="Ribbon Test" Height="474" Width="849" MinHeight="300" MinWidth="400" >
    <Grid>
        <fluent:Ribbon CanMinimize="False" CanQuickAccessLocationChanging="False" AutomaticStateManagement="false"
                       x:Name="ribbon">
            <fluent:RibbonTabItem   x:Name="test1TabItem"
                                    Header="Test1"
                                    KeyTip="I">
                <fluent:RibbonGroupBox Header="Group1" Height="84" Width="248" TabIndex="0">
                    <fluent:Button Name="Test">
                        <StackPanel VerticalAlignment="Stretch"
                                HorizontalAlignment="Center">
                            <Path Width="40"
                                Height="40"
                                Stretch="Uniform"
                                Fill="Black"
                                Data="M 10,100 C 10,300 300,-200 300,100" />
                            <TextBlock><Run Text="Test Button" /></TextBlock>
                        </StackPanel>
                    </fluent:Button>
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Group2" VerticalAlignment="Stretch" Height="84" Width="98" TabIndex="1">
                </fluent:RibbonGroupBox>
            </fluent:RibbonTabItem>
            <fluent:RibbonTabItem   x:Name="test2TabItem"
                                    Header="Test2"
                                    KeyTip="O">
            </fluent:RibbonTabItem>
        </fluent:Ribbon>
    </Grid>
</Controls:MetroWindow>

and here how it looks like (the Button is there and i can click on it but there is no text and no icon)

enter image description here


Solution

  • Sorry for the late response. It took me some time to get the library running. It seems that you could set the LargeIcon

    <fluent:Button Name="Test">
        <fluent:Button.LargeIcon>
            <Path Width="40"
                    Height="40"
                    Stretch="Uniform"
                    Fill="Black"
                    Data="M 10,100 C 10,300 300,-200 300,100" />
        </fluent:Button.LargeIcon>
        Test Button 1
    </fluent:Button>
    

    Don't forget: You can always extract a Controls default template. You can than look up how the control is build inside. How to Extract Default Control Template In Visual Studio?