How to link MediaCapture source with CaptureElement using Caliburn.Micro?

In Windows Phone 8.1, I use the first approach of the Caliburn.Micro model, but since the view model cannot have any idea of ​​the view, I don’t see how I can bind the MediaCapture object to the CaptureElement in the view.

+4
source share
4 answers

I had the same problem. I am using MVVM Light with Windows Phone 8.1 WinRT (Universal Apps).

I used ContentControl and is bound to CaptureElement:

 <ContentControl HorizontalAlignment="Left"         
                Width="320" Height="140" Content="{Binding CaptureElement}"/>

CaptureElement and MediaCapture are properties in my ViewModel:

private MediaCapture _mediaCapture;
        public MediaCapture MediaCapture
        {
            get
            {
                if (_mediaCapture == null) _mediaCapture = new MediaCapture();
                return _mediaCapture;
            }
            set
            {
                Set(() => MediaCapture, ref _mediaCapture, value);
            }
        }
        private CaptureElement _captureElement;
        public CaptureElement CaptureElement
        {
            get
            {
                if (_captureElement == null) _captureElement = new CaptureElement();
                return _captureElement;
            }
            set
            {
                Set(() => CaptureElement, ref _captureElement, value);
            }
        }

And then I call ConfigureMedia () in the ViewModel constructor:

   async void ConfigureMedia()
    { 
        await MediaCapture.InitializeAsync();
        CaptureElement.Source = MediaCapture;
        await MediaCapture.StartPreviewAsync();
    }

MediaCapture, Source , , StartPeview. :)

+8

/, .

?

<CaptureElement Source="{Binding SomeMediaCapture}" />

, , CaptureElement. , .

<CaptureElement custom:CaptureHelper.Source="{Binding SomeMediaCapture}" />

, - html.

, , (, ICaptureView), .

,

var captureView = (ICaptureView) GetView();

ICaptureView SetCaptureSource. , , ICaptureView .

+1

Hawlett, , . ConfigureMedia() :

private async void ConfigureMedia()
{
    _deviceInformationCollection = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
    await MediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
    {
        VideoDeviceId = _deviceInformationCollection[_deviceInformationCollection.Count - 1].Id
        // The rear-facing camera is the last in the list
    });
    MediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Photo;
    MediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
    CaptureElement.Source = MediaCapture;
    CaptureElement.Stretch = Stretch.UniformToFill;
    await MediaCapture.StartPreviewAsync();
}
+1

ContentControl CaptureElement, , . , , . StopPreviewAsync() .

0

Source: https://habr.com/ru/post/1542098/


All Articles