I've a problem initializing video capturing in my mobile. I want to capture the video stream to preview in mobile and get captures to read codes like QR, BarCodes...
I've mark the capabilities Webcam, Microphone and VideosLibrary (I think it's not needed but I marked to test).
MainPage.xaml
<Page
x:Class="App2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Button Click="Button_Click"/>
<CaptureElement Grid.Row="1" x:Name="myCaptureElement"/>
</Grid>
</Page>
MainPage.xaml.css
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
public async Task StartCapture()
{
try
{
var _mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync();
myCaptureElement.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
}
catch (Exception ex)
{
throw;
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//StartCapture().Wait();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await StartCapture();
}
}
I've tested in the click event and in the OnNavigatedTo and it fails in the same way.
If I test in mobile device I've the following error when press F10 on InitializeAsync call:
{System.UnauthorizedAccessException: Access is denied.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at App2.MainPage.<StartCapture>d__0.MoveNext()}
I've read a lot of articles with solucions like gant more Permisions, set devideId, configure settings, ... and all of this fails again.
In some places inform this is a problema with the versión Back of WP8.1 Preview and suggest to install Cyan version and others said it's not needed
¿How can I capture images? ¿there are more people with the same problem?
Thanks a lot
Related
Hi I'm trying to play a sound on tapping of an image but it is not playing.
Actually here i'm also using one media element to play a sound on this page continuously. It is playing but other which should be played on tapping of image is not playing.Any idea would be appreciated.
Xaml code
<MediaElement x:Name="mycontrol" Source="/Audio/bg_sound.mp3" AutoPlay="True"/>
<MediaElement x:Name="mediaElement1" />
C# Code
public sealed partial class Home : Page
{
public Home()
{
this.InitializeComponent();
}
private void L_color_tap(object sender, TappedRoutedEventArgs e)
{
mediaElement1.Source = new Uri("ms-appx:///Assets/LearnColor/Objectnamesmp3/colors.mp3");
mediaElement1.AutoPlay = true;
this.Frame.Navigate(typeof(L_Col_Act));
}
}
<MediaElement x:Name="mycontrol" Source="/Audio/bg_sound.mp3" AutoPlay="True"/>
<MediaElement x:Name="mediaElement1" Source="/Assets/LearnColor/Objectnamesmp3/colors.mp3" AutoPlay="False" />
And in c# code you can change it to
public sealed partial class Home : Page
{
public Home()
{
this.InitializeComponent();
}
private void L_color_tap(object sender, TappedRoutedEventArgs e)
{
mycontrol.Stop();
mediaElement.Play();
}
}
and this [this.Frame.Navigate(typeof(L_Col_Act));] Navigation code can go in your media ended Event for mediaElement1.
Hope this may help you.
Only one MediaElement allowed to play at a time.
Please refer to this link:
https://msdn.microsoft.com/library/windows/apps/hh202883(v=vs.105).aspx
When you add a flyout for a button control, for example, after you tap on that button the flyout is displayed with a transition animation which depends on the Placement property of the flyout. If the Placement is set to Top the animation looks like drop down from that button. In my case I would like to either remove the animation altogether or make it expanding by x and y from that button. How to do that?
There is a similar case:How to change ContentDialog transition.
As Rob Caplan said,You cannot override the transitions in the ContentDialog, etc. They are designed to be easy ways to get standard behaviour and will always use the PopupThemeTransition.
So if you want non-standard behaviour then you can write a custom control which uses your own TransitionCollection or without Transition.
For example:
<UserControl
x:Class="Is_it_possible_to_remove_or_change_default_flyou.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Is_it_possible_to_remove_or_change_default_flyou"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
LostFocus="UserControl_LostFocus">
<UserControl.Transitions>
<TransitionCollection>
<!--Add the Transition that you want-->
</TransitionCollection>
</UserControl.Transitions>
<Grid Name="MyGrid" BorderBrush="Gray" BorderThickness="1" Background="LightGray">
<StackPanel>
<TextBox Name="MyText" Text="Hello"></TextBox>
<TextBox Text="!"></TextBox>
</StackPanel>
</Grid>
</UserControl>
The code behind:
public sealed partial class MyUserControl1 : UserControl
{
public Popup hostPopup;
public double actHei;
public double actWei;
public MyUserControl1()
{
this.InitializeComponent();
hostPopup = new Popup();
hostPopup.Child = this;
}
public void Show()
{
hostPopup.IsOpen = true;
actHei = MyGrid.ActualHeight;
actWei = MyGrid.ActualWidth;
MyText.Focus(FocusState.Pointer);
}
private void UserControl_LostFocus(object sender, RoutedEventArgs e)
{
hostPopup.IsOpen = false;
}
}
In MainPage code behind:
public sealed partial class MainPage : Page
{
public MyUserControl1 popup;
public MainPage()
{
this.InitializeComponent();
popup = new MyUserControl1();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (popup.hostPopup.IsOpen != true)
{
var ttv = MyButton.TransformToVisual(Window.Current.Content);
Point screenCoords = ttv.TransformPoint(new Point(0, 0));
popup.hostPopup.VerticalOffset = screenCoords.Y - 100;
popup.hostPopup.HorizontalOffset = screenCoords.X;
popup.Show();
}
}
}
Contrary to what Rob Caplan and Jayden statet it is actually possible to override the default Transition of a ContentDialog.
You can create a class extending the ContentDialog and subscribe to to Loading event as shown in the code below.
There you can override the Transitions of the newly created popup for the ContentDialog.
I know this is a late answer and this might be a bit of a hacky solution but since I was looking for it I hope I can help somebody.
Example Code (no xaml):
public class CustomContentDialog : ContentDialog {
public CustomContentDialog() {
Loading += (sender, args) => {
// gets the background rectangle and the popup containing the ContentDialog
var popups = VisualTreeHelper.GetOpenPopups(Window.Current);
// remove all transitions and childtransitions from the popups
foreach (var p in popups) {
p.ChildTransitions = new TransitionCollection {
// your transitions
};
p.Transitions = new TransitionCollection {
// your transitions
};
}
};
}
}
I want to prototype an interface for touchscreen so that I can record every mouse click during the user test.
I suceeded in making storyboard, but failed in logging mouse click.
I looked up other questions -
How do I get the current mouse screen coordinates in WPF?, How do I get the current mouse screen coordinates in WPF? -
but couldn't understand how to apply those codes to .xaml or code-behind file(I got error message every trial.)
If I want to record where testers click on the canvas, how can I track coordinates and export logs to other file format?
A really simple example,
This will record every position the user has clicked and when :
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="525"
Height="350"
MouseDown="MainWindow_OnMouseDown">
<Grid>
<Button Width="75"
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="Button_Click"
Content="_Show log" />
</Grid>
</Window>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
namespace WpfApplication6
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly List<Tuple<DateTime, Point>> _list;
public MainWindow()
{
InitializeComponent();
_list = new List<Tuple<DateTime, Point>>();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
IEnumerable<string> #select = _list.Select(s => string.Format("{0} {1}", s.Item1.TimeOfDay, s.Item2));
string #join = string.Join(Environment.NewLine, #select);
MessageBox.Show(join);
}
private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
{
Point position = e.GetPosition((IInputElement) sender);
var tuple = new Tuple<DateTime, Point>(DateTime.Now, position);
_list.Add(tuple);
}
}
}
I am developing a windows 8.1 app using VS 2013 and MVVM Light.
The following code shows the behavior in a flyout within an appbar:
<AppBarButton.Flyout>
<Flyout x:Name="FlyoutCalculator"
Placement="Top"
FlyoutPresenterStyle="{StaticResource FlyoutPresenterBaseStyle}">
<uc:Calculator ApplyCommand="{Binding CancelCommand}"
CancelCommand="{Binding CancelCommand}"
Available="{Binding AvailableCounter, Mode=OneWay}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"/>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Opening">
<core:InvokeCommandAction Command="{Binding ShowCurrentCostsCommand}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Flyout>
</AppBarButton.Flyout>
Unfortunately I get an exception while compiling the app:
WinRT-Informationen: Cannot add instance of type Microsoft.Xaml.Interactions.Core.EventTriggerBehavior to a collection of type Microsoft.Xaml.Interactivity.BehaviorCollection
Other Behaviors in the View do work, does someone know a solution to this?
Extremely late answer here, but I had the same issue and came up with a solution after finding this post.
I just created a custom behavior specifically for flyouts, used like this. OpenActions will execute when the flyout is opened, and CloseActions will execute when the flyout closes. In this case, I wanted the bottom app bar to not be visible when the flyout was open.
<Flyout Placement="Full">
<i:Interaction.Behaviors>
<behaviors:FlyoutBehavior>
<behaviors:FlyoutBehavior.OpenActions>
<core:ChangePropertyAction PropertyName="Visibility" Value="Collapsed" TargetObject="{Binding ElementName=CommandBar}" />
</behaviors:FlyoutBehavior.OpenActions>
<behaviors:FlyoutBehavior.CloseActions>
<core:ChangePropertyAction PropertyName="Visibility" Value="Visible" TargetObject="{Binding ElementName=CommandBar}" />
</behaviors:FlyoutBehavior.CloseActions>
</behaviors:FlyoutBehavior>
</i:Interaction.Behaviors>
<Grid>
...
</Grid>
</Flyout>
Code is here:
class FlyoutBehavior : DependencyObject, IBehavior
{
public DependencyObject AssociatedObject { get; private set; }
public void Attach(Windows.UI.Xaml.DependencyObject associatedObject)
{
var flyout = associatedObject as FlyoutBase;
if (flyout == null)
throw new ArgumentException("FlyoutBehavior can be attached only to FlyoutBase");
AssociatedObject = associatedObject;
flyout.Opened += FlyoutOpened;
flyout.Closed += FlyoutClosed;
}
public void Detach()
{
var flyout = AssociatedObject as FlyoutBase;
if (flyout != null)
{
flyout.Opened -= FlyoutOpened;
flyout.Closed -= FlyoutClosed;
}
}
public static readonly DependencyProperty OpenActionsProperty =
DependencyProperty.Register("OpenActions", typeof(ActionCollection), typeof(FlyoutBehavior), new PropertyMetadata(null));
public ActionCollection OpenActions
{
get { return GetValue(OpenActionsProperty) as ActionCollection; }
set { SetValue(OpenActionsProperty, value); }
}
public static readonly DependencyProperty CloseActionsProperty =
DependencyProperty.Register("CloseActions", typeof(ActionCollection), typeof(FlyoutBehavior), new PropertyMetadata(null));
public ActionCollection CloseActions
{
get { return GetValue(CloseActionsProperty) as ActionCollection; }
set { SetValue(CloseActionsProperty, value); }
}
private void FlyoutOpened(object sender, object e)
{
foreach (IAction action in OpenActions)
{
action.Execute(AssociatedObject, null);
}
}
private void FlyoutClosed(object sender, object e)
{
foreach (IAction action in CloseActions)
{
action.Execute(AssociatedObject, null);
}
}
public FlyoutBehavior()
{
OpenActions = new ActionCollection();
CloseActions = new ActionCollection();
}
}
I do not have a solution but:
I'm not using Flyouts in my Windows 8.1 App, I'm using a UserControl on which I have added a EventTriggerBehavior as you did. And I get exactly the same Errormessage from VisualStudio at runtime.
As I am using a RoutedEventHandler this could cause the Problem as you use
EventHandler<object> Opening
as the Trigger for the Behavior. But that is just an idea of what is the problem.
For me I have found an answer:
I have changed the Type of my RoutedEventHandler to be just a normal EventHandler. And the Method inside the CodeBehind which triggers the RoutedEventHandler is invoked with only the sender, because I dont know how to convert RoutedEventArgs into EventArgs, but as long as I dont need the EventArgs it's not a problem.
You could also make a workaround by creating a UserControl with a Flyout Control and make the Opening Event public to the Page where you use it. Then you can add the EventTriggerBehavior to the UserControl and connect it to your custom Opening Event and you should get the expected behavior.
I am having a strange issue where creating my class that derives from Caliburn.Micro.Autofac.AutofacBootstrapper in my App.xaml fails with a build error:
The tag 'Bootstrapper' does not exist in XML namespace 'clr-namespace:TestProject'
But if I just create the bootstrapper in App.xaml.cs everything works.
The code below shows what I can do to make things work. If I uncomment the Bootstrapper in the App.xaml and comment out the one in the App.xaml.cs I get the build error.
How are the two any different?
Intellisense is happy with the Bootstrapper in the App.xaml I only get the error on build.
Heres is my App.xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestProject"
x:Class="TestProject.App"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<!--
<local:Bootstrapper x:Key="Bootstrapper"/>
-->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
and here is my App.xaml.cs
namespace TestProject
{
public partial class App : Application
{
public App()
{
new Bootstrapper();
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
// If the app is running outside of the debugger then report the exception using
// the browser's exception mechanism. On IE this will display it a yellow alert
// icon in the status bar and Firefox will display a script error.
if (!System.Diagnostics.Debugger.IsAttached)
{
// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
}
}
private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
{
try
{
string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", #"\n");
System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
}
catch (Exception)
{
}
}
}
}
and here is Bootsteapper.cs
namespace TestProject
{
public class Bootstrapper : AutofacBootstrapper<MainPageViewModel>
{
public Bootstrapper()
{
base.ConfigureBootstrapper();
EnforceNamespaceConvention = false;
ViewModelBaseType = typeof(IShell);
}
protected override void ConfigureContainer(Autofac.ContainerBuilder builder)
{
builder.RegisterType<MainPageViewModel>();
base.ConfigureContainer(builder);
}
}
}
Have you tried to set your bootstrapper beyond the MergedDictionaries?
<Application.Resources>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Assembly;component/OtherResource.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>