2016-11-14 145 views
2

对于我的GUI,我使用fluentribbonmahapps,并希望在带有图标的功能区中有按钮。我想使用像this(不是文件)的xaml图标。所以我需要在流畅的按钮中设置Path。我尝试以下,但它不工作 - 巴顿是 空(无文本并显示没有图标):在fluentribbon按钮中设置xaml图标

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

更新

下面是完整的代码:

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

这里如何它看起来像(按钮在那里,我可以点击它,但没有文字和没有图标)

enter image description here

+1

不工作=? – Mat

+0

请尝试创建[mcve]。你发布的代码工作得很好。 – Mat

+0

我更新了我的问题 – MrWoffle

回答

2

对不起,迟到的回应。我花了一些时间让图书馆运行。看起来你可以设置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> 

不要忘了:你总是可以提取一个控件的默认模板。您可以查看内部控件的构建方式。 How to Extract Default Control Template In Visual Studio?

+0

它的作品谢谢 – MrWoffle