我在我的WPF应用程序中使用Dragablz选项卡控件。 下面的代码在我的App.xaml昨天晚上运行良好,但是当我今天加载项目,它显示我这个错误:
属性元素不能位于元素内容的中间。 他们必须在内容之前或之后。
<Application x:Class="MVCP.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz" StartupUri="FloatingActivator.xaml"> <Application.Resources> <ResourceDictionary> <Style x:Key="OpenSans"> <Setter Property="TextElement.FontFamily" Value="Open Sans, /MVCP;component/Fonts/#Open Sans" /> </Style> <ResourceDictionary.MergedDictionaries> <!-- primary color --> <ResourceDictionary> <!-- include your primary palette --> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Indigo.xaml" /> </ResourceDictionary.MergedDictionaries> <!-- include three hues from the primary palette (and the associated forecolours). Do not rename, keep in sequence; light to dark. --> <SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/> <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/> <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource Primary500}"/> <SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/> <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary700}"/> <SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary700Foreground}"/> </ResourceDictionary> <!-- secondary colour --> <ResourceDictionary> <!-- include your secondary pallette --> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Yellow.xaml" /> </ResourceDictionary.MergedDictionaries> <!-- include a single secondary accent color (and the associated forecolour) --> <SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent200}"/> <SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent200Foreground}"/> </ResourceDictionary> <!-- Include the Dragablz Material Design style --> <ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/> </ResourceDictionary.MergedDictionaries> <!-- tell Dragablz tab control to use the Material Design theme --> <Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}" /> <Style x:Key="FileItemStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="Margin" Value="5,5,5,5"/> <Setter Property="Padding" Value="0,0,0,0"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Height="50" > <Border x:Name="border" BorderBrush="{x:Null}" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="2.5"/> <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <ContentPresenter/> </StackPanel> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> </Application.Resources> </Application>
原因很简单:首先添加样式“OpenSans”,然后设置MergedDictionary属性,然后再添加两个样式。 要修复,就像这样重新排序:
<Application x:Class="MVCP.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz" StartupUri="FloatingActivator.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <!-- primary color --> <ResourceDictionary> <!-- include your primary palette --> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Indigo.xaml" /> </ResourceDictionary.MergedDictionaries> <!-- include three hues from the primary palette (and the associated forecolours). Do not rename, keep in sequence; light to dark. --> <SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/> <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/> <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource Primary500}"/> <SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/> <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary700}"/> <SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary700Foreground}"/> </ResourceDictionary> <!-- secondary colour --> <ResourceDictionary> <!-- include your secondary pallette --> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Yellow.xaml" /> </ResourceDictionary.MergedDictionaries> <!-- include a single secondary accent color (and the associated forecolour) --> <SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent200}"/> <SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent200Foreground}"/> </ResourceDictionary> <!-- Include the Dragablz Material Design style --> <ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/> </ResourceDictionary.MergedDictionaries> <Style x:Key="OpenSans"> <Setter Property="TextElement.FontFamily" Value="Open Sans, /MVCP;component/Fonts/#Open Sans" /> </Style> <!-- tell Dragablz tab control to use the Material Design theme --> <Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}" /> <Style x:Key="FileItemStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="Margin" Value="5,5,5,5"/> <Setter Property="Padding" Value="0,0,0,0"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Height="50" > <Border x:Name="border" BorderBrush="{x:Null}" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="2.5"/> <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <ContentPresenter/> </StackPanel> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> </Application.Resources>