如果此錯誤在使用功能區控件的類中的new()方法中斷時,出現Ribbon控件庫的錯誤。Microsoft Ribbon窗口拋出異常
類型「System.TypeInitializationException」的一個例外發生在WpfPluggableApp.exe但在用戶代碼
附加信息沒有被處理的:關於「Microsoft.Windows.Controls.Ribbon.RibbonWindow」的類型初始值扔一個例外。
但是,當我繼續我得到這個錯誤,而不是
型「System.Windows.Markup.XamlParseException」未處理的異常發生在PresentationFramework.dll
附加信息:「調用類型'WpfPluggableApp.MainWindow'中與指定的綁定約束匹配的構造函數拋出異常。'行號「3」和行位置「5」。
沒有什麼我可以看到這是會在MainWindow.Xaml的3線來實現它:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<Menu Name="mnu" DockPanel.Dock="Top">
</Menu>
<TabControl ItemsSource="{Binding Path=ViewModels}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="IsSelected" Value="{Binding Path=isSelected,Mode=TwoWay}"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<DockPanel MinWidth="120">
<Button
Command="{Binding Path=CloseCommand}"
Content="X"
Cursor="Hand"
DockPanel.Dock="Right"
Focusable="False"
FontFamily="Courier"
FontSize="9"
FontWeight="Bold"
Margin="0,1,0,0"
Padding="0"
VerticalContentAlignment="Center"
Width="16" Height="16"
IsTabStop="False"
/>
<ContentPresenter Margin="10"
Content="{Binding Path=DisplayName}"
VerticalAlignment="Center"
/>
</DockPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Content" Value="{Binding}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</DockPanel>
下面是功能區中的XAML:
<ribbon:RibbonWindow x:Class="MainRibbonWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="MainRibbonWindow"
x:Name="MainRibbonWindow"
WindowState="Maximized" MinHeight="480" MinWidth="640">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ribbon:Ribbon x:Name="Ribbon">
</ribbon:Ribbon>
<TabControl Grid.Row="1" ItemsSource="{Binding Path=ViewModels}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="IsSelected" Value="{Binding Path=isSelected,Mode=TwoWay}"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<DockPanel MinWidth="120">
<Button
Command="{Binding Path=CloseCommand}"
Content="X"
Cursor="Hand"
DockPanel.Dock="Right"
Focusable="False"
FontFamily="Courier"
FontSize="9"
FontWeight="Bold"
Margin="0,1,0,0"
Padding="0"
VerticalContentAlignment="Center"
Width="16" Height="16"
IsTabStop="False"
/>
<ContentPresenter
Content="{Binding Path=DisplayName}"
VerticalAlignment="Center"
/>
</DockPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<!--<Setter Property="Content" Value="{Binding}" />-->
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
它可能是一種情況需要一雙新鮮的眼睛來看它!如果您能看到問題,請告訴我。
感謝, 山姆
-----------------------編輯-------------- ---------------------------
問題已解決,我引用了錯誤的類庫。