Creo el xaml de mi user control, en este caso mi UserControl se encargara de dibujar adentro suyo el contenido que se le pase como parámetro. Ademas recibirá un Binding como parámetro el cual hará que se muestre o no un ActivityIndicator
<?xml version="1.0" encoding="UTF-8"?> <ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="WhereAreYouMobile.UserControls.LoadingUserControl"> <ContentView.Content> <StackLayout> <ActivityIndicator IsVisible="{Binding IsBusy}" HorizontalOptions="Center" VerticalOptions="Center" Color="Red" IsRunning="{Binding IsBusy}" ></ActivityIndicator> <Frame HeightRequest="900" Padding="0" Margin="0" OutlineColor="Transparent" HasShadow="False" x:Name="ContentFrame" IsVisible="{Binding IsBusy,Converter={StaticResource NegateBooleanConverter}}" > </Frame> </StackLayout> </ContentView.Content> </ContentView>
La propiedad Binding, es la que recibido como parámetro desde el exterior. Para hacer uso de ella debo de crear una Propiedad Bindable
public static readonly BindableProperty InputProperty = BindableProperty.Create(nameof(InputView), typeof(bool), typeof(LoadingUserControl), false, BindingMode.Default, null, InputPropertyChanged); private static void InputPropertyChanged(BindableObject bindable, object oldValue, object newValue) { var self = (LoadingUserControl)bindable; self.IsBusy = (bool)newValue; }
La propieadad que recibo del exterior será la Input.
Para utilizar mi UserControl :
<userControls1:LoadingUserControl Input="{Binding IsBusy,Mode=TwoWay}"> </userControls1:LoadingUserControl>