Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramatically create a Popup with a Child element initialised by Caliburn Micro
    primarykey
    data
    text
    <p><code>Windows.Media.Captures</code> has a handy <code>CameraCaptureUI</code> class that can be instantiated as follows to show a dialog to the user to capture photos or videos:</p> <pre><code>// Create dialog to Capture Video CameraCaptureUI dialog = new CameraCaptureUI(); dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { // Do something with file... } </code></pre> <p>I would like to create my own custom audio capture class that works in a very similar way:</p> <pre><code>// Create dialog to Capture Audio AudioCaptureUI dialog = new AudioCaptureUI(); StorageFile file = await dialog.CaptureFileAsync(); if (file != null) { // Do something with file... } </code></pre> <p>To do the above, I created the following three files:</p> <ul> <li><code>AudioCaptureUI</code> - The class that a user instantiates to show the audio capture dialog</li> <li><code>AudioCaptureView</code> - UI View for the audio capture experience</li> <li><code>AudioCaptureViewModel</code> - ViewModel that contains all the audio capture logic</li> </ul> <p>To create a full screen audio capture dialog, I have figured out that the best way is to use a <code>Popup</code> and set its child to the <code>AudioCaptureView</code>. The problem I have with this approach is that it is pushing me use a View-First pattern. Since I am using Caliburn Micro, I wanted to be able to use CM to instantiate a View by creating the ViewModel first.</p> <p>What I currently have is something on the following lines:</p> <pre><code>public class AudioCaptureUI { private Popup _popup; private TaskCompletionSource&lt;StorageFile&gt; _taskCompletionSource; public IAsyncOperation&lt;StorageFile&gt; CaptureFileAsync() { // Force my View to be full screen AudioCaptureView audioCaptureView = new AudioCaptureView { Width = Window.Current.Bounds.Width, Height = Window.Current.Bounds.Height }; // Creating View, instead of a ViewModel. Renders Caliburn Micro useless! _popup = new Popup { Child = audioCaptureView }; if (_popup.Child != null) { SubscribeEvents(); _popup.IsOpen = true; } return AsyncInfo.Run(WaitForInput); } ... } </code></pre> <p>The above pattern works. However, I am forced to wire all my actions manually and cannot leverage Caliburn Micro's MVVM goodness.</p> <p>How else should I instantiate a ViewModel programatically from my <code>AudioCaptureUI</code> class?</p> <p>It is also important to highlight that I am working on a <strong>Windows Store app</strong> and using the WinRT CM port.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload