I am using a scrollviewer having stackpanel with 10 low quality images .When flick once the image moves to the next and load the high resolution image of the viewed image in that view. The problem is when flick 6 times continuously,scroll moves 6 times and the method for add high resolution occurs 6 times and load the image in view. I need an idea to wait for the completed flick for some seconds and execute the high resolution add image method once. Is there any way to do that?
You can delay the loading of the high resolution images using a timer.
The code might look something like this:
DispatcherTimer timer = new DispatcherTimer();
public MainPage()
{
InitializeComponent();
timer.Interval = TimeSpan.FromSeconds(1); //You can adjust the delay suitable to your needs
timer.Tick += new EventHandler(timer_Tick);
}
void handle_Flick(object sender, GestureEventArgs args)
{
//If timer is not running, start the timer
//and do everything else other than loading high-resolution image.
if(timer.IsEnabled != true)
{
//start the timer
timer.Start();
}
}
void timer_Tick(object sender, EventArgs e)
{
//Stop the timer
timer.Stop();
//Load the high resolution image
}
Related
I would like to control the speed and direction of the slide's transitions in a Carousel view. I can automatially make the slides transitions but I don't know how to control its speed nor the direction of the transition (Right to Left).
Any idea?
thanks in advance
I Start a timer to scroll each page :
public ItemsPage()
{
InitializeComponent();
_timer = new System.Timers.Timer();
_timer.Interval = 15000;
_timer.Elapsed += _timer_Elapsed;
_timer.Enabled = true;
}
After the time expires I set the new page:
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
System.Console.WriteLine("{0} Position.", Position);
Position = Position + 1;
Position = Position % Carousel_Mycloset.Count;
OnPropertyChanged("Position");
}
The pages are scroll but I cannot control the speed and direction (right to left) of the transition.
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 a ScrollViewer which is partly covered by an image in my Windows Phone 8 app. Now when you begin scrolling on the image it works just like when begin scrolling outside of the image. But I want to prevent the ScrolLViewer from scrolling when the drag movement starts on the image. The image is a partly transparent png file, but the same behaviour occurs when I replace it with a rectangle.
How can I do this with WP8?
You'll have to attach event handlers to the Image's MouseLeftButtonDown, MouseLeave, and MouseLeftButtonUp to disable and then re-enable the ScrollViewer's vertical/horizontal scrolling.
private void Image_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
private void Image_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
}
private void Image_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
}
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();
}
I'm creating a practice application that plays a sound every so often seconds and as a button is pressed it decreases the time interval for the sound to play. For example at the start it plays a sound every 15 seconds and when I press the button it should now play the sound every 10 seconds. Basically every time the user presses the button it decreases the interval by 5 seconds. So I have a DispatcherTimer at the top of my class and created its interval and Tick method when the page loads like such. I also have an int variable for the seconds in the time span.
DispatcherTimer timer = new DispatcherTimer();
int interval = 15;
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
timer.Interval = new TimeSpan(0, 0, interval);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void btn_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
interval -= 5;
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, interval);
}
But this makes the sound play crazily. Is there a proper way to do this?
if this is your actual code then Larry is quite right... u have to call timer.stop(); before starting the second.
also give some condition so as to disallow interval < 0
Do you cancel the first dispatcher timer before you start the second? Is it possible that after the first click you have two dispatcher timers firing?