BaseContentPage with custom ActivityIndicator

Hi everyone

I have a BaseContentPage which inherits ContentPage, and all other pages inherit this Base-class. This is done so every page automatically has a custom ActivityIndicator available.
The custom ActivityIndicator is a regular class which inherits nothing but contains a method "CreateLoadingIndicator" and returns a RelativeLayout - its children are 1) the current content, 2) a new instance of ActivityIndicator and 3) a Label with information what is happening. This will create an overlay on top of the content with the ActivityIndicator in the middle of the screen:

`public RelativeLayout CreateLoadingIndicator(View content)
{
RelativeLayout rl = new RelativeLayout();

if (content != null)
{
    rl.Children.Add(content,
        Constraint.RelativeToParent((parent) =>
        {
            return 0;
        }),
        Constraint.RelativeToParent((parent) =>
        {
            return 0;
        }),
        Constraint.RelativeToParent((parent) =>
        {
            return parent.Width;
        }),
        Constraint.RelativeToParent((parent) =>
        {
            return parent.Height;
        })
    );
}

rl.Children.Add(_activityIndicator,
    Constraint.RelativeToParent((parent) =>
    {
        return (parent.Width / 2) - (_activityIndicator.Width / 2);
    }),
    Constraint.RelativeToParent((parent) =>
    {
        return (parent.Height / 2) - (_activityIndicator.Height / 2);
    })
);

rl.Children.Add(_lblInformation,
    Constraint.RelativeToParent((parent) =>
    {
        return 0;
    }),
    Constraint.RelativeToParent((parent) =>
    {
        return (parent.Height / 2) + (_activityIndicator.Height / 2) + _lblInformation.Height;
    })
);

return rl;

}`

So basically right now in the Code Behind of my page I can simply call "CustomActivityIndicator.SetVisible(true)" and BAM the overlay is visible. In other words it works like a charm.

The problem is that recently I've implemented MVVM in my solution so I want almost no code in the Code Behind; everything has to be done inside the ViewModel. This ViewModel doesn't know of the CustomActivityIndicator, only BaseContentPage and everything that inherits this CustomContentPage do...

Is there any way I can add binding to my CustomActivityIndicator so I can call "ViewModel.IsBusy = true" and the Custom-class will trigger?

Best Answer

Answers

Sign In or Register to comment.