在WPF中创建窗口时,尝试将TabControl放入Grid时出现以下错误:
错误1属性元素不能位于元素中间 内容。它们必须在内容之前或之后。
开发平台:Windows-7:Visual Studio 2008
XAML代码:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="USBTOOL"
Title="Window1"
Height="768" Width="1300" ResizeMode="NoResize">
<UserControl>
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="1" CornerRadius="4,4,4,4" BorderBrush="#FF8C8E94" Background="#8C208AB0" Margin="8,20.66,10,0" Height="51" VerticalAlignment="Top" TextElement.FontWeight="Bold" TextElement.FontFamily="Comic Sans MS" TextElement.FontSize="18" TextElement.Foreground="#FF000000" OpacityMask="{x:Null}" x:Name="TopTitleMenu"/>
<Border BorderThickness="1"
CornerRadius="6,6,6,6" BorderBrush="#FF8C8E94" Background="#8C208AB0" Margin="8,76,10,10" TextElement.FontWeight="Bold" TextElement.FontFamily="Comic Sans MS" TextElement.FontSize="18" TextElement.Foreground="#FF000000" OpacityMask="{x:Null}"/>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="-0.072,-0.118">
<GradientStop Color="#FF132734" Offset="0"/>
<GradientStop Color="#FF072E42" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<TabControl> </TabControl>
</Grid>
</UserControl>
</Window>
答案 0 :(得分:0)
TabControl不是问题。问题是
<Grid.Background>
...
</Grid.Background>
像这样设置Grid的属性必须在Gird控件的所有内容之前或之后发生。
只需将TabControl声明移到Grid.Background上方即可。