Aymen Ragoubi
Aymen Ragoubi

Reputation: 396

WPF ribbon ImageSource

I try to do a ribbon ToolBar. My probem is that it doesn't found ImageSource. Here is my simple code:

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

Also I declared the MainWindow.xaml.cs as follow:

public partial class MainWindow : RibbonWindow

the message error is that it doesn't found a path to Mydirectory/BooksDemo/Image.

Why it doesn't work. Could someone help me please.

Upvotes: 3

Views: 2363

Answers (1)

cYOUNES
cYOUNES

Reputation: 936

Use this :

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

You have to replace your_assembly_name by the assembly name without extension.

EDIT:

Also be sure that your image is built as Resources in the files parameters by setting Build action field to Resources : enter image description here

Upvotes: 2

Related Questions