本文介绍了如何使用Caliburn.Micro将源MediaCapture绑定到CaptureElement?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows Phone 8.1上,我使用的是Caliburn.Micro view-model-first方法,但是由于视图模型无法完全了解视图,因此我看不到如何将MediaCapture对象绑定到CaptureElement中。视图。

On Windows Phone 8.1, I am using the Caliburn.Micro view-model-first approach, but as the view model cannot have any knowledge of the view, I cannot see how I can bind a MediaCapture object to a CaptureElement in the view.

推荐答案

我遇到了同样的问题。我在Windows Phone 8.1 WinRT(通用应用程序)中使用了MVVM Light。

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

我使用ContentControl并绑定到CaptureElement:

I used ContentControl and binded to CaptureElement:

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

CaptureElement和MediaCapture是我的ViewModel中的属性:

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);
            }
        }

接下来,我在ViewModel的构造函数中调用ConfigureMedia():

And next I call ConfigureMedia() in ViewModel's constructor:

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

重要的是首先初始化MediaCapture,然后设置Source,最后是StartPeview。对我来说,它有效:)

It's important to firstly initialize MediaCapture, next set Source and finally StartPeview. For me it works :)

这篇关于如何使用Caliburn.Micro将源MediaCapture绑定到CaptureElement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 17:41