Within a Windows Phone 7 app, is it possible to capture the hardware camera button pressed event in code?
Right now when I press the camera button nothing happens and I can't figure out how to hook up to the event.
Yes you can. Check this link. This is an example of the events:
// The event is fired when the shutter button receives a half press.
CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress;
// The event is fired when the shutter button receives a full press.
CameraButtons.ShutterKeyPressed += OnButtonFullPress;
// The event is fired when the shutter button is released.
CameraButtons.ShutterKeyReleased += OnButtonRelease;
// Provide auto-focus with a half button press using the hardware shutter button.
private void OnButtonHalfPress(object sender, EventArgs e)
{
if (cam != null)
{
// Focus when a capture is not in progress.
try
{
this.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = "Half Button Press: Auto Focus";
});
cam.Focus();
}
catch (Exception focusError)
{
// Cannot focus when a capture is in progress.
this.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = focusError.Message;
});
}
}
}
Related
On my button click event I subscribe my messaging center
bool isDataReceived = false;
MessagingCenter.Subscribe<Dimention>(this, "Print", (sender) =>
{
isDataReceived = true;
PopulateData(sender);
if (isDataReceived)
{
MessagingCenter.Unsubscribe<Dimention>(this, "Print");
}
});
I am sending the data from a Popup Window
MessagingCenter.Send<Dimention>(data, "Print");
But how to unsubscribe the messaging center when user press hardware back button without sending values.
You can override the BackButton event
protected override bool OnBackButtonPressed()
{
base.OnBackButtonPressed();
MessagingCenter.Unsubscribe<Dimention>(this, "Print");
return false;
}
You can also make sure that you are unsubscribing from the messaging center by adding the code to the OnDisappearing method:
protected override void OnDisappearing()
{
base.OnDisappearing();
MessagingCenter.Unsubscribe<Dimention>(this, "Print");
}
I'm using MediaCapture element for video capturing in UWP. However, I cannot find how can I embed this time element (Screenshot is available at here)
to the video. I'm using a Dispatcher to tick and show the time:
DispatcherTimer timer = new DispatcherTimer(); // Timer for clock.
timer.Interval = TimeSpan.FromSeconds(1); // timer ticks in one second.
timer.Tick += Timer_Tick; // Tick event handler.
timer.Start(); // Start the timer.
private void Timer_Tick(object sender, object e)
{
DateTime_Text.Text = DateTime.Now.ToString("G");// Printing datetime on page.
} // Show time in main screen with tick.
Are anyone knows how can I embed this Tick event to MediaCapture ?
Thanks.
I have Sprite object that is a poker chip. When the user clicks it the bid increase. I am increasing the bid on the MouseUp event. But if the user starts a click outside of the object/chip and then drags the mouse over the chip and does MouseUp, it fires the function mapped to MouseUp. How can I prevent it from firing if the click starts outside of the object.
this.addEventListener(MouseEvent.MOUSE_DOWN, pressChipDown)
this.addEventListener(MouseEvent.MOUSE_UP, pressChipUp)
this.addEventListener(MouseEvent.MOUSE_OUT, pressChipOut)
private function pressChipDown(e:MouseEvent):void
{
super.x = startX + 5;
super.y = startY + 5;
}
private function pressChipUp(e:MouseEvent):void
{
increaseBid();
super.x = startX;
super.y = startY;
}
private function pressChipOut(e:MouseEvent):void
{
if(e.buttonDown) //if mouse button is down, move chip back but dont increase bid
{
pressChipUp(MouseEvent.MOUSE_OUT as MouseEvent)
}
}
Thanks
On roll over, start listening to mouse down and mouse up, if up before down, it's a "fake"
this.addeventlistener(MouseEvent.ROLL_OVER, onOver)
...
How do we grab the event that is generated when the inputscope of a TextBox is set to search and the Arrow is pressed?
1.There is an event OnKeyDown where you can check what key is pressed
textBox.OnKeyDown += (s, e) =>
{
if (e.Key == Key.Enter)
{
// perform search
e.Handler = true;
}
}
2.ScrollViewer automatically scrolls to focused textbox, I guess...
Is there a way I can detect this? I want to keep performing an action as long as the user is holding on an icon.
Instead of using the GestureListener for this you could instead use the mouse manipulation events to detect how long to perform your action. For instance:
Listen for MouseLeftButtonDown to know when the user has touched the icon
Keep performing the action until either MouseLeftButtonUp or MouseLeave fire indicating that the user is no longer touching that icon
You may also have to play with MouseEnter for initiating the action
Today only i did the same thing in my project.I'll tell you the basic logic what i implemented(assuming it has to be done on button).Step 1: On the button _ManipulationStarted_ event start a timer with the interval after which you want to fire the repeat action.
Step 2: On the button _ManipulationCompleted_ event stop the timer.
Step 3: If the timer is fired,stop the timer and start another timer with interval = the repeat interval for your action.And inside the second timer fire handler perform your operation only if the control has focus. In this case, where the control is a button, you can check if the button.IsPressed is true then perform action.
The code will look something like:
Button forward=new Button();
DispatcherTimer forwardHoldTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(2) };
forward.ManipulationStarted += (a, b) => { forwardHoldTimer.Start(); };
forward.ManipulationCompleted += (c, d) => { forwardHoldTimer.Stop(); };
forwardHoldTimer.Tick+=(s1,e1)=>
{
forwardHoldTimer.Stop();
DispatcherTimer t = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(100) };
t.Tick += (x, y) =>
{
if (forward.IsPressed)
{
//Your action logic will go here
}
else
t.Stop();
};
t.Start();
};
Hope this helps.
NOTE: Amresh Kumar was correct in suggesting using the manipulation events. Also, I was given the same advice on the Windows Phone App Hubs forums so I've edited this post to reflect the code changes.
Before, the UX was flaky because lifting my finger off the screen didn't always trigger a cancellation. Not surprisingly, the GestureCompleted code in the toolkit appears to be better geared towards touchscreens than are mouse button events.
XAML:
<iconControls:iconUpDownArrow>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Tap="RangeUpTap" Hold="RangeUpHold" GestureCompleted="RangeUpCancel" />
</toolkit:GestureService.GestureListener>
</iconControls:iconUpDownArrow>
code:
private void RangeUpTap(object sender, GestureEventArgs e)
{
RangeIncrementUp(sender, e);
}
private readonly TimeSpan _rangeIncrementTimeSpan = new TimeSpan(1500000);
private readonly DispatcherTimer _rangeIncrementTimer = new DispatcherTimer();
private void RangeUpHold(object sender, GestureEventArgs e)
{
_rangeIncrementTimer.Interval = _rangeIncrementTimeSpan;
_rangeIncrementTimer.Tick += RangeIncrementUp;
_rangeIncrementTimer.Start();
}
private void RangeUpCancel(object sender, GestureEventArgs e)
{
_rangeIncrementTimer.Stop();
_rangeIncrementTimer.Tick -= RangeIncrementUp;
}
private void RangeIncrementUp(object sender, EventArgs e)
{
int range = Convert.ToInt32(tBoxRange.Text);
if (range < 1000)
{
range += 10;
}
tBoxRange.Text = range.ToString();
}