I am reading code from a WPF project which has the following XAML code (I have omitted the boilerplate parts):
<Window x:Class="AdornedControlSample.Window1"
...
x:Name="window"
...
>
<Canvas
Grid.Row="1"
x:Name="canvas"
>
...
Please note that there is no Grid
defined whatsoever anywhere in this XAML file. So, my questions are:
Grid.Row="1"
within the Canvas
definition?x:Name="window"
serve? I have not seen anything in the code-behind that references a window
. (There are references to Window1
, though.)Question 1
In your example, Grid.Row
has no purpose at all. You gave it a value, but that value will not be used because there is no Grid
around the Canvas
. It also doesn't give an error because it is a valid property/value.
The RowProperty
is defined in the Canvas
class.
Question 2
It gives a unique name (within the window itself) to the UI-element. For now, it has no purpose. So you can remove it safely. However, if you want to access the window in the code-behind of the view, the x:name
serves a purpose. But you can also access the window via the this
keyword.