2016-01-26 34 views
2

我嘗試做一個功能區ToolBar。我的探頭是它沒有找到ImageSource。 這裏是我的簡單的代碼:WPF緞帶ImageSource

<RibbonWindow x:Class="BooksDemo.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:BooksDemo" 
    Title="Books Demo App" Height="400" Width="600"> 

<Ribbon DockPanel.Dock="Top" > 
    <Ribbon.QuickAccessToolBar> 
     <RibbonQuickAccessToolBar> 
      <RibbonButton Command="local:BooksCommands.ShowBook" /> 
      <RibbonButton Command="local:BooksCommands.ShowBooksList" /> 
     </RibbonQuickAccessToolBar> 
    </Ribbon.QuickAccessToolBar> 

    <Ribbon.ApplicationMenu> 
     <RibbonApplicationMenu > 
      <RibbonApplicationMenuItem Header="Show _Book" /> 
      <RibbonSeparator /> 
      <RibbonApplicationMenuItem Header="Exit" Command="Close" /> 
     </RibbonApplicationMenu> 
    </Ribbon.ApplicationMenu> 


    <RibbonTab Header="Home"> 
     <RibbonGroup Header="Clipboard"> 
      <RibbonButton Command="Paste" Label="Paste" SmallImageSource="Images/cut.png" /> 
      <RibbonButton Command="Cut" SmallImageSource="Images/cut.png" /> 
      <RibbonButton Command="Copy" SmallImageSource="Images/copy.png" /> 
      <RibbonButton Command="Undo" LargeImageSource="Images/undo.png" /> 
     </RibbonGroup> 

       <RibbonGroup Header="Show"> 


      <RibbonButton LargeImageSource="Images/one.png" Label="Book" /> 
      <RibbonButton LargeImageSource="Images/list.png" Label="Book List" /> 
      <RibbonButton LargeImageSource="Images/grid.png" Label="Book Grid" /> 

     </RibbonGroup> 
    </RibbonTab> 

    <RibbonTab Header="Ribbon Controls"> 
     <RibbonGroup Header="Sample"> 
      <RibbonButton Label="Button" /> 
      <RibbonCheckBox Label="Checkbox" /> 
      <RibbonComboBox Label="Combo1"> 
       <Label>One</Label> 
       <Label>Two</Label> 
      </RibbonComboBox> 
      <RibbonTextBox>Text Box</RibbonTextBox> 
      <RibbonSplitButton Label="Split Button"> 
       <RibbonMenuItem Header="One" /> 
       <RibbonMenuItem Header="Two" /> 
      </RibbonSplitButton> 
      <RibbonComboBox Label="Combo2" IsEditable="False"> 
       <RibbonGallery SelectedValuePath="Content" MaxColumnCount="1" SelectedValue="Green"> 
        <RibbonGalleryCategory> 
         <RibbonGalleryItem Content="Red" Foreground="Red" /> 
         <RibbonGalleryItem Content="Green" Foreground="Green" /> 
         <RibbonGalleryItem Content="Blue" Foreground="Blue" /> 
        </RibbonGalleryCategory> 
       </RibbonGallery> 
      </RibbonComboBox> 
     </RibbonGroup> 
    </RibbonTab> 
</Ribbon>    

而且我宣佈MainWindow.xaml.cs如下:

public partial class MainWindow : RibbonWindow 

消息的錯誤是,它並沒有找到路徑mydirectory中/ BooksDemo /圖像。

爲什麼它不起作用。請有人幫助我。

回答

1

使用此:

<RibbonButton LargeImageSource="pack://application:,,,/your_assembly_name;component/Images/grid.png" Label="Book Grid" /> 

你必須裝配名稱,而不擴展到更換your_assembly_name

編輯:

另外要確保你的形象是通過設置生成操作領域的資源建成資源在文件中的參數: enter image description here

+0

謝謝你的答案,但它不工作。我注意到,當我通過功能區更改RibbonWindow時,它識別圖像,但它當然不起作用! –

+0

@AymenRagoubi你可以在這裏複製你遇到的錯誤嗎? – Younes

+0

消息錯誤是「找不到路徑的一部分'mypath \ Images \ one.png' 爲什麼它在解決方案目錄中查找圖像? 我應該添加對ribbon組件的引用嗎? –