WPF seems unrecognized and causes errors [duplicate]
Clash Royale CLAN TAG#URR8PPP
WPF <Border> seems unrecognized and causes errors [duplicate]
This question already has an answer here:
I am new in C# but was a programmer many years ago. I have "played" and searched a lot to understand what's wrong here:
<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>
Where:XLS0415 = The attachable property 'Resources' was not found in type 'Grid'.
XDG0012 = The member "Resources" is not recognized or is not accessible.
and same for RowDefinitions
and ColumnDefinitions
.
XLS0415 = The attachable property 'Resources' was not found in type 'Grid'.
XDG0012 = The member "Resources" is not recognized or is not accessible.
RowDefinitions
ColumnDefinitions
It seems only InteliSense recognizes <Border>
, while the XAML interpreter (or whatever it's called?) DOES NOT.
I've tried moving / modifying the <Border>
statements in any way I could think of, cut&pasted 3 working examples - always with the same (or similar) problems
<Border>
<Border>
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
<Border>
<Grid>
<Border>
@Itay1, It is not specific to Border or Grid, it is XAML rule of property tag syntax:
elementTypeName.propertyName
. see the link to MS docs which I posted under the answer– ASh
Aug 12 at 13:52
elementTypeName.propertyName
1 Answer
1
<Grid.Resources>
and <Grid.RowDefinitions>
tags state that Resources and RowDefintions are being added to Grid. Therefore <Grid.Resources>
and <Grid.RowDefinitions>
properties can be nested only inside <Grid>
tag. After you defined those properties, define nested children element[s] like <Border>
<Grid.Resources>
<Grid.RowDefinitions>
<Grid.Resources>
<Grid.RowDefinitions>
<Grid>
<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>
Wow, It works! Thanks for the solution & explanantion! <br> I ran across lots of examples placing
<Border>
immediately INSIDE <Grid>
, and none immediately OUTSIDE of it. I wonder how all of them did not fail, as they did when I merely cut&pasted them?!– Itay1
Aug 12 at 10:53
<Border>
<Grid>
@Itay1, I recomment to take a look at MS docs here: XAML syntax in detail. if my answer helped, please mark it as accepted
– ASh
Aug 12 at 13:51
Thanks @ASh. I tried reading it and remembered why I quit programming and became a product designer 25 years ago, and 8 years later became a psychotherapist. I am now an
<Amateur reputation="2"/>
and you are helping me understand that is where I want to stay. :))– Itay1
Aug 12 at 14:34
<Amateur reputation="2"/>
While it does not answer my question directly, it DOES show how to do what I wanted, as I now understand this is not an issue about
<Border>
, but basic knowledge about<Grid>
s . That's why my searches didn't come across it, though I DID find at least 3 places showing<Border>
right AFTER `<Grid> opening statement, not BEFORE. If this is a reason to damage my reputation, I hope I become more worthy someday :) Thanks and sorry.– Itay1
Aug 12 at 10:46