c# - 将 TabControl 放在 Grid 内会出现错误
问题描述
在 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>
解决方案
TabControl 不是问题。问题是
<Grid.Background>
...
</Grid.Background>
像这样为 Grid 设置属性必须在 Grid 控件的所有内容之前或之后进行。
只需将 TabControl 声明移到 Grid.Background 上方即可。
推荐阅读
- amazon-web-services - 在 Codebuild 中构建和发布 dotnet 核心应用程序
- vuetify.js - 将 Vuetify 与 Jhipster 一起使用
- c# - 如何在 Windows 11 中使用 win32 或 uwp 在任务栏中制作动画图标
- sql - 带有 IN 运算符的 Suitescript SuiteQL 错误
- reactjs - 组件在 react-native 中保持重新渲染
- heroku - Heroku 和电子邮件/Gmail
- html - 如何在 Angular 中更改 ngx-mat-datetime-picker 的宽度和高度?
- assembly - 32位mingw找不到任何符号
- android - CameraX:如何设置 PreviewView 的背景?
- python - 将 xml 文件的条目转换为 pandas 数据框