在 Visual Studio 11 中使用 .NET 4.5 构建我的 WPF 应用程序时,我在 Visual Studio 中收到一个奇怪的错误。
我的 WPF XAML 标记如下:
<RibbonWindow x:Class="Fablelane.DesktopApplication.CreateStory"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Create new story" Height="468" Width="526">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Ribbon>
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu>
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<RibbonTab Margin="0" Header="Format">
<RibbonGroup Header="Font">
<StackPanel Orientation="Horizontal">
<RibbonComboBox>
<RibbonGallery SelectedValue="Heading 1"
SelectedValuePath="Content"
MaxColumnCount="1">
<RibbonGalleryCategory>
<RibbonGalleryItem Content="Heading 1" Foreground="#16ea00" FontSize="20" />
<RibbonGalleryItem Content="Heading 2" Foreground="#00c6ff" FontSize="18" />
<RibbonGalleryItem Content="Heading 3" Foreground="#999999" FontSize="16" />
<RibbonGalleryItem Content="Heading 3" Foreground="#707070" FontSize="14" />
<RibbonGalleryItem Content="Content" Foreground="#FF606060" />
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonComboBox>
</StackPanel>
<RibbonControlGroup Margin="2">
<RibbonToggleButton Label="B"
FontWeight="Bold" FontFamily="Times New Roman" Padding="2" />
<RibbonToggleButton Label="I"
FontStyle="Italic" FontFamily="Times New Roman" Padding="2" />
<RibbonToggleButton Label="U" FontFamily="Times New Roman" Padding="2,2,2,0" />
</RibbonControlGroup>
</RibbonGroup>
</RibbonTab>
<RibbonTab Margin="0" Header="Options">
</RibbonTab>
</Ribbon>
<RichTextBox Grid.Row="1">
</RichTextBox>
</Grid>
</RibbonWindow>
现在,当我构建时,我收到错误:
未知的构建错误,来自程序集“System.Windows.Controls.Ribbon,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089”的“System.Windows.Controls.Ribbon.RibbonGallery”类型中的“方法“get_Command”没有一个实现。
当我从代码中删除 RibbonGallery 元素时,它编译并运行得很好。
应该注意的是,我可以很容易地在 Visual Studio 中看到设计器视图渲染得很好,其中包含 RibbonGallery 元素。它只是在构建过程中失败。