Tuesday, October 28, 2014

How to turn on/off the flashlight in Win8.1 tablet

Try this out:


<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="TorchButton" Content="Turn Torch On" Click="TorchButton_Click"/>
</Grid>


MediaCapture MyMediaCapture = new MediaCapture();

private async void TorchButton_Click(object sender, RoutedEventArgs e)
{
await MyMediaCapture.InitializeAsync();
var MyVideoDeviceController = MyMediaCapture.VideoDeviceController;
var MyTorch = MyVideoDeviceController.TorchControl;

if (MyTorch.Supported)
{
if ((TorchButton.Content as string) == "Turn Torch On")
{
TorchButton.Content = "Turn Torch Off";
MyTorch.PowerPercent = 100;
MyTorch.Enabled = true;
}
else
{
TorchButton.Content = "Turn Torch On";
MyTorch.PowerPercent = 0;
MyTorch.Enabled = false;
}
}
else
{
TorchButton.Content = "Torch not supported!";
}
}
}







Matt Small - Microsoft Escalation Engineer - Forum Moderator

If my reply answers your question, please mark this post as answered.



NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.


No comments:

Post a Comment