1

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.

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

Itay1
  • 37
  • 1
  • 3
  • 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 ``, but basic knowledge about ``s . That's why my searches didn't come across it, though I DID find at least 3 places showing `` right AFTER ` 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 '18 at 10:46
  • @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 '18 at 13:52

1 Answers1

2

<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>

<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>
ASh
  • 34,632
  • 9
  • 60
  • 82
  • Wow, It works! Thanks for the solution & explanantion!
    I ran across lots of examples placing `` immediately INSIDE ``, 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 '18 at 10:53
  • @Itay1, I recomment to take a look at MS docs here: [XAML syntax in detail](https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/xaml-syntax-in-detail#property-element-syntax). if my answer helped, please mark it as accepted – ASh Aug 12 '18 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 `` and you are helping me understand that is where I want to stay. :)) – Itay1 Aug 12 '18 at 14:34