我尝试做一个功能区工具栏。我的问题是它没有找到 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/Image 的路径。
为什么它不起作用。有人可以帮我吗?
最佳答案
使用这个:
<RibbonButton LargeImageSource="pack://application:,,,/your_assembly_name;component/Images/grid.png" Label="Book Grid" />
您必须将 your_ assembly_name 替换为不带扩展名的程序集名称。
编辑:
关于WPF 功能区 ImageSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35015076/