Simply open Xamarin Studio and create a new "Forms ContentView Xaml", name it MyView, that is our UserControl.
In the code below we use the UserControl inside a Xaml Page.
Without adding any code to the UserControl the page can interact with it setting its content (the label "Hello From the page").
With this approach the page decided to replace the content of the UserControl, any view added within the UserControl by xaml in itself will be ignored. The UserControl can still be extended using it's c# code-behind.
In the code below we use the UserControl inside a Xaml Page.
Without adding any code to the UserControl the page can interact with it setting its content (the label "Hello From the page").
With this approach the page decided to replace the content of the UserControl, any view added within the UserControl by xaml in itself will be ignored. The UserControl can still be extended using it's c# code-behind.
<?xml version="1.0" encoding="UTF-8"?> <local:MyPageBase xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xam0001.MyPage1" xmlns:local="clr-namespace:xam0001"> <local:MyView> <Label Text="Hello From the page"></Label> </local:MyView> </local:MyPageBase>
Commenti