我是C#的新手,但多年以前还是一名程序员。我“玩过”游戏并进行了大量搜索以了解这里出了什么问题:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Margin="0">
<Grid>
<Border> <-- any time this is here
<Grid.Resources> <-- this gets XLS0415 + XDG0012
...
</Grid.Resources>
<Grid.RowDefinitions> <-- this gets XLS0415 + XDG0012
...
</Grid.RowDefinitions>
<Border> <-- any time this is here
<Grid.ColumnDefinitions> <-- this gets XLS0415 + XDG0012
...
</Grid.ColumnDefinitions>
<Grid.RowDefinitions> <-- this gets XLS0415 + XDG0012
...
</Grid.RowDefinitions>
</Border>
</Grid>
</Border>
</Grid>
</Window>
其中:
XLS0415 = The attachable property 'Resources' was not found in type 'Grid'.
XDG0012 = The member "Resources" is not recognized or is not accessible.
和RowDefinitions
和ColumnDefinitions
相同。
似乎只有InteliSense可以识别<Border>
,而XAML解释器(或任何它称为的东西)却不能。
我试图以我能想到的任何方式移动/修改<Border>
语句,剪切并粘贴了3个工作示例-总是遇到相同(或相似)的问题
答案 0 :(得分:0)
<Grid.Resources>
和<Grid.RowDefinitions>
标签指出正在将Resources和RowDefintions添加到Grid。因此,<Grid.Resources>
和<Grid.RowDefinitions>
properties 只能嵌套在<Grid>
标记内。定义这些属性后,请定义嵌套的 children元素[s] ,例如<Border>
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Margin="0">
<Grid>
<Grid.Resources>
...
</Grid.Resources>
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<Border>
<Grid>
<Grid.ColumnDefinitions>
...
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<Border>
</Border>
</Grid>
</Border>
</Grid>
</Window>