You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _drafts/2019-01-25-Showing-Gridlines-In-Xamarin-Forms-Previewer.md
+14-7
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,22 @@ published: false
5
5
6
6
This blog post describes how to show make a Xamarin.Forms `Grid` show its columns and rows graphically in the Visual Studio XAML Preview.
7
7
8
-
One of the things about the Previewer that has always frustrated me is that it doesn't show the outlines of any of the objects that I place in a form.
8
+
One of the things about the XAML Previewer that has always frustrated me is that it doesn't show the outlines of any of the objects that I place in a form. It's much easier to visualise what's going on if we can see the objects in a form even when they have no content.
9
9
10
-
A simple way to visualise the grid is to create some `BoxView` objects, give them `BackgroundColor`, and add them to the `Grid`. However, it's easy to see that this is ugly, prone to errors (I have accidentally shipped something with a hot pink background at least once) and extremely tedious.
10
+
A simple way to visualise the grid is to create some `BoxView` objects, give them `BackgroundColor`, and add them to the `Grid` in any spots where the grid is not obvious.
11
11
12
-
Xamarin.Forms objects are cross-platform virtualisations that draw on each platform by means of a Renderer. Delving into the source of Xamarin Forms revealed that the `Grid` object is a subclass of `Layout<View>`, but unusually it has no renderer of its own. This is because all it does is manage a collection of child views and arrange them grid-fashion in its parent view.
12
+
However, it's easy to see that this is ugly and prone to errors.
13
+
14
+
- It adds objects to the visual tree that are only needed at design time.
15
+
- There is a significant risk that these objects will appear in the live app when we don't want them to.
16
+
17
+
To provide a good solution to these issues we need something that can display the details of a `Grid` at design-time, but is invisible in a live app.
18
+
19
+
Xamarin.Forms objects are cross-platform virtualisations that draw on each platform by means of a Renderer. Delving into the source of Xamarin.Forms shows that the `Grid` object is a subclass of `Layout<View>`, but unusually it has no renderer of its own. This is because all it does is manage a collection of child views and arrange them grid-fashion in its parent view.
13
20
14
21
Most Xamarin.Forms objects are open for subclassing. The `Grid` object definitely is, so we can subclass it in our platform-independent code to make a `PreviewGrid`:
0 commit comments