0

I am creating a control based on a generic View that works with a custom renderer based on an iOS MPVolumeView, which is the simple control that allows you to select an alternate output route for audio in your app (i.e. Bluetooth Speaker). The code works just fine if I wrap inside a single stack layout, but not if it's inside two stack layouts. My XAML looks like this... very basic:

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DABApp.DabTestPage" xmlns:local="clr-namespace:DABApp;assembly=DABApp">
<ContentPage.Content>
    <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="Red">
        <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="FillAndExpand">
            <local:AudioOutputView />
        </StackLayout>
    </StackLayout>
</ContentPage.Content>
</ContentPage>

And here's the guts of my custom renderer:

[assembly: ExportRenderer(typeof(AudioOutputView), typeof(iosAudioOutputViewRenderer))]
namespace DABApp.iOS
{
public class iosAudioOutputViewRenderer: ViewRenderer<AudioOutputView, UIView>
{
    MPVolumeView view;

    protected override void OnElementChanged(ElementChangedEventArgs<AudioOutputView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            view = new MPVolumeView()
            {
                ShowsRouteButton = true,
                ShowsVolumeSlider = false,

            };
            SetNativeControl(view);
        }
    }
}
}

With this XAML and code, when I push the page onto the nav stack async, the page won't even show. If I remove one of the StackLayouts, it works fine.

I changed my IOS control in the CustomRenderer to a simple UILabel and this works fine... so it looks like it has something to do with putting the MPVolumeView inside 2 StackLayouts. I need to be able to do this because of the layout requirements of my app, and it doesn't make any sense why 1 StackLayout is fine, but 2 isn't, and only for this native control.

Any ideas?

Chet at C2IT
  • 549
  • 6
  • 21
  • I wonder if it is a sizing issue? Can you try using `Center` and `Fill` for the inner `StackLayout`? E.g. HorizontalOptions="Center" VerticalOptions="Fill"> – jgoldberger - MSFT Feb 22 '17 at 00:39
  • I think I may have already tried this but I'm not sure. We'll be circling back to this down the road in a few weeks, and I'll post back here if it does the trick. – Chet at C2IT Feb 22 '17 at 03:15

0 Answers0