Get the delta value from PointeWheelChanged event for WinRT - windows-runtime

Is there any way to get the delta value from PointeWheelChanged event in WinRT?

The following works in the RTM of Windows Runtime, it will log the result to the Debug window. Positive values are up (away from you), negative values are scrolling down (towards you). Important is to set handled to true so that this event doesn't bubble further up the UI elements.
private void ZoomPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.GetCurrentPoint(this).Properties.MouseWheelDelta);
e.Handled = true;
}

Following code works well,
private void PointerWheelChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
{
var wheelDelta = args.CurrentPoint.Properties.MouseWheelDelta;
// do something with the delta
}

Related

FirstRun info in JSON (WP)

i have a problem with the info of a JSON in Windows Phone.
I want to show if the app is running for the first time, and if not, don't show anything.
This is my function to show info on the JSON:
async void NavigationService_Navigated(object sender, NavigationEventArgs e)
{
if (e.IsNavigationInitiator
|| !e.IsNavigationInitiator && e.NavigationMode != NavigationMode.Back)
{
var navigationInfo = new
{
Mode = e.NavigationMode.ToString(),
From = this.BackStack.Any() ? this.BackStack.Last().Source.ToString() : string.Empty,
Current = e.Uri.ToString(),
};
var jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(navigationInfo);
await this.currentApplication.Client.PageView(jsonData);
}
}
I want to add one more thing where is Mode, From and Current. I want to add IsFirstRun that give as True if it's the first time i open the app.
I've seen this for firstRun function, but i don't know how to put it in my code.
public static bool IsFirstRun()
{
if (!settings.Contains(FIRST_RUN_FLAG)) //First time running
{
settings.Add(FIRST_RUN_FLAG, false);
return true;
}
return false;
}
I need help... thanks!
It is pretty simple if you want to create a flag for First Run,
In App.xaml.cs
Look for a function named
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
What we want to do is create a flag inside this function and only set it to true if it doesn't exist. Like so.
using System.IO.IsolatedStorage; // include this namespace in App.xaml.cs
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
if (!IsolatedStorageSettings.ApplicationSettings.Contains("first_run"))
{
IsolatedStorageSettings.ApplicationSettings.Add("first_run", true);
}
else
{
// set the flag to flase
IsolatedStorageSettings.ApplicationSettings["first_run"] = false;
}
// save
IsolatedStorageSettings.ApplicationSettings.Save();
}
Now if you want to do something on first run all you have to do is check the settings again like so:
bool first_run = (bool) IsolatedStorageSettings.ApplicationSettings["first_run"];
For debugging cases you will probably want to remove the flag so it will hit first_run again by doing this
// remove the flag and save
IsolatedStorageSettings.ApplicationSettings.Remove("first_run");
IsolatedStorageSettings.ApplicationSettings.Save();

Check if a new row is added to a DataGridView

I download data from my server and use a DataGridView to present the result. When a new row is added, I’d like my program to show a signal. How can I do that?
Subscribe to the DataGridView.RowsAdded event.
dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
// show the signal
}
You need to use userAddedRow event , when activate that event you can use it to send
boolean like true or false like this Example
private void usersDGV_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
//this event occurs when user added new row to the datagridview
//and will turn the boolean newRowAdded on.
newRowAdded = true;
}

How do I refresh/update a LongListSelector after removing a MenuItem (on Windows Phone 8)?

I am trying to delete a MenuItem from a LongListSelector in my Windows Phone 8 app. The MenuItems play various sounds when clicked and I want the user to be able to delete them.
There are two panels on the app. The second panel records a new sound and puts the recording on the LongListSelector as a new MenuItem.
Problem: After I do the delete the display looks exactly the same and the sound still plays! However, if I record a new sound (switching to the new recording panel) then the deletion works with the deleted MenuItem gone.
How do I force the update/refresh of the LongListSelector to unload/delete the MenuItem and associated sound data resident on the GUI?
The following code is called from from the MenuItem's click event. The LongListSelector is named 'CustomSounds':
private void DeleteSoundClick(object sender, RoutedEventArgs e)
{
var menuItem = sender as MenuItem;
if (menuItem == null) return;
var soundData = menuItem.DataContext as SoundData;
if (soundData == null) return;
if (soundData.FilePath.Contains(CustomSounds.Name))
{
CustomSounds.ItemsSource.Remove(soundData);
}
this.LayoutRoot.UpdateLayout();
}
Inverse your thing. Set item source with new list.
private void DeleteSoundClick(object sender, RoutedEventArgs e)
{
var menuItem = sender as MenuItem;
if (menuItem == null) return;
var soundData = menuItem.DataContext as SoundData;
if (soundData == null) return;
if (soundData.FilePath.Contains(CustomSounds.Name))
{
MyNewList.remove(soundData);
CustomSounds.ItemsSource = myNewList;
}
this.LayoutRoot.UpdateLayout();
}
Create local variable and set your itemsource in constructor.
Other thing :
create an updated list :
private ObservableCollection<Sound> _myNewList;
public ObservableCollection<Sound> MynewList{
get
{
return _myNewList;
}
set
{
_myNewList= value;
RaisePropertyChanged(MynewList);
}
Bind this in your listbox :
<listbox itemSource="{Binding MyNewList" SelectedItem="{Binding SelectedSound,mode=twoway}>
Create selectedSound:
private Sound _selectedSound;
public Sound SelectedSound{
get
{
return _selectedSound;
}
set
{
_selectedSound= value;
RaisePropertyChanged(SelectedSound);
}
Delete item :
private void DeleteSoundClick(object sender, RoutedEventArgs e)
{
if(SelectedSound != null){
Mynewlist.remove(SelectedSound);
}
}
:D
ObservableCollection is nothing more than a collection with notification that when something is changed in the collection, it lets the UI know. It's just a ItemSource, so your LongListSelector is populated by the OC...
I had the same issue, however, I used simple List.
Solution was easy - just created new object of the List
var newList = new List<TheModel>();
newList.AddRange(originalList);
TheLongListSelector.ItemsSource = newList;
TheLongListSelector.UpdateLayout();
originalList was list with removed item.
It's not the most efficient way, but it works. I think that's no problem for small data.

Deregister the EventHandler in Windows Phone 8 application

I am using this piece of code to register the event and want to de-register Event after completing it's task but don't know how to do problem is that I am using local object for registering event..
code..
public void loadData()
{
//Here client is loacal object..
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AccessTokenDownloadCompleted);
}
void AccessTokenDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
}
If I understood you correctly, you want to remove your event handler after the download is completed. To remove an event handler, all you need to do is:
client.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(AccessTokenDownloadCompleted);
Note the -= instead of +=.
Place this code where the download completes and you should be fine.
Maybe you can try this:
public void loadData()
{
//Here client is loacal object..
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AccessTokenDownloadCompleted);
}
void AccessTokenDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Client client = sender as Client;
if(client != null)
client.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(AccessTokenDownloadCompleted);
}

while loop ignore the event listener

so when i run this code to try to change the background the GUI crashes and gets stuck in a infinite while loop ignoring the event listeners. here is the code:
private Panel getPanel1() {
if (panel1 == null) {
panel1 = new Panel();
panel1.setLayout(new GridBagLayout());
while(frame.isVisible()){
panel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
frame.setVisible(false);
}
});
int r = (int) (Math.random()*255);
int g = (int) (Math.random()*255);
int b = (int) (Math.random()*255);
Color c = new Color(r, g, b);
panel1.setBackground(c);
try {
Thread.sleep(4000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
panel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
/*panel1.setVisible(false);
frame.setVisible(false);*/
System.exit(0);
}
});
}
}
return panel1;
}
instead of exiting the loop of terminating the program or event changing the background it just displays the panel and does nothing else and i have to force it to quit. what should i do?
You're effectively blocking the UI thread by calling sleep in a loop. In that loop you're also adding two listeners on every iteration too, which is quite bizarre.
Don't block the UI thread. Let the GUI framework take care of delivering events etc. Basically you need to take an event-based approach to UI, rather than the approach you currently are taking, which will never let any events get despatched (as you're never returning control to the caller).
Create the panel, add the appropriate event listener, and then just return it to the caller. If you want to change the background colour every 4 seconds, you should do that via a timer so that it's not blocking the UI thread waiting for the 4 seconds to elapse.