I was missing namespace - I cleaned up my code and it removed Input asset - that's why it didn't work.
UWP C# On Key down not working properly.
I am wondering why action "OnKeyDown" is not working properly.
When I use this class the calculations of my program goes wierd with "NaN" besides a concrete number.
How to make any key down calculate price?
Universal Windows Platform (UWP)
-
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-21T07:37:23.803+00:00 Do you make custom control and OnKeyDown
OnKeyDown
visual method ? -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-21T07:41:00.687+00:00 Could you mind share your code that you have used for listen OnKeyDown action?
-
VoyTec 671 Reputation points
2021-06-22T23:40:24.617+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
private void KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) { calculate(); } private void calculate() { to_square_meter = price_square_meter.Value; zero_three = (width.Value * height.Value) / 1000000; cprice_net.Value = price_net.Value * quantity.Value; var price_net_value_change = price_net.Value; price_net.Text = String.Format("{0:0.00}", price_net_value_change); gross calculation = price_net.Value * 1.23; price_gross_text.Text = "GROSS price: " + String.Format("{0:0.00}", gross_calculation) + "euro"; }
-
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-23T01:23:07.37+00:00 During the testing, if the control has been focused, KeyDown will be invoked, please check if it was focused before press keyboard.
-
VoyTec 671 Reputation points
2021-06-23T04:14:24.423+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
Can you elaborate? I am a beginner, what do you mean by that? -
VoyTec 671 Reputation points
2021-06-23T04:34:14.977+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
Do you mean System.Boolean IsFocusedEngaged?
It can't be triggered, even if I trigger it my app crashes. -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-23T06:28:08.627+00:00 Ok, could tell which control
KeyDown
event that you want listen? could you share your xaml code ? -
VoyTec 671 Reputation points
2021-06-23T06:35:15.267+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
<muxc:NumberBox x:Name="height" HorizontalAlignment="Left" Margin="6,163,0,0" VerticalAlignment="Top" Width="76" Foreground="#FF200493" ValueChanged="height_vc" Grid.Row="2" Grid.Column="1" KeyDown="test"/>
not much to be honest, should I have something there?
If I check "IsFocusEngaged" it deslects back but it puts code inside xaml object, andy my app crashes with it. -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-23T06:44:15.713+00:00 KeyDown="test"
could be triggered when the cursor flash in the box. -
VoyTec 671 Reputation points
2021-06-23T06:49:48.18+00:00 no, my cursor hoover over the box when typing and still not working... :/
@Nico Zhu (Shanghai Wicresoft Co,.Ltd.) -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-23T07:14:52.24+00:00 That's interesting, can you make blank sample test it, I'm afraid other control has handled this event.
-
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-23T09:53:04.127+00:00 could you mind share a sample that could reproduce this problem ?
-
VoyTec 671 Reputation points
2021-06-23T20:22:26.117+00:00 Thank you fore help so far.
I ma istalling VS 2022P maybe that will work on it...
@Nico Zhu (Shanghai Wicresoft Co,.Ltd.) -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-24T01:21:50.94+00:00 Ok. please let me know the test result.
-
VoyTec 671 Reputation points
2021-06-24T14:35:22.257+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
It didn\t solve my problem.
When I will have more of free time I will share my code with you.
thanks! -
VoyTec 671 Reputation points
2021-06-24T19:48:35.833+00:00 My project is on GitHub now. I need your nickname to make you a collaborator cause I made it private.
@Nico Zhu (Shanghai Wicresoft Co,.Ltd.) -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-25T01:48:18.327+00:00 Due to our policy, it is not suitable to make a forum support a collaborator of your private project.
We don't want to check your whole project because it might contain your private information. What we need is just a minimal, reproducible example. Please create a blank project. Then just add the necessary code which is used to reproduce the issue inside the project. Then you could share the sample in public with us. -
VoyTec 671 Reputation points
2021-06-25T18:07:34.797+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
I don't know how i managed to make UI.Xaml Nuget for NumbeBox working in my original project, cause I made new project to show you the error and my number box won't show at all now... :/ -
VoyTec 671 Reputation points
2021-06-27T20:05:08.55+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
I figured out another way to do my program.
Can you show me how to make periodic event - every 1 second do something? -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-06-30T02:50:00.277+00:00 Can you show me how to make periodic event - every 1 second do something?
Sure, you could use DispatcherTimer to approach, here is sample code.
dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += dispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
For more please refer official document.
-
VoyTec 671 Reputation points
2021-06-30T18:54:15.767+00:00 @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
My project doesn't recognize "Threading" and "dispatcherTimer".
I used System.Threading and System.Timers and it didn't help. -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-07-01T02:03:34.893+00:00 It's my fault, I have updated the document, please use DispatcherTimer under
Windows.UI.Xaml
namespace. -
VoyTec 671 Reputation points
2021-07-01T12:08:57.1+00:00 Thanks @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
I will check it out as soon as I return home. -
Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2021-07-09T02:16:53.883+00:00 Does it works, Any updates for this topic.
-
VoyTec 671 Reputation points
2021-08-23T19:20:17.663+00:00 OK @Nico Zhu (Shanghai Wicresoft Co,.Ltd.)
Back to the problem.
I thought with 2022 or Win11 would fix the issues but it didn't.- Key down still not working: I have keydown event but it works after few click and not for the first time and mostly for ENTER.
- Dispatcher needs some libraries (namespaces) cause it doesnt recognize the code, can you share it with me?
Thanks
Sign in to comment
-
VoyTec 671 Reputation points
2021-09-20T18:10:22.827+00:00