I have a problem with debug my app.There is no eror, I debug the app on device it start's but when I tap the button debug error!
that's how i use it:
In .xaml file:
<Button Name="taxi1" Content="Call Taxi 1" Click="taxi1_Click" />
in .xaml.cs file:
private void taxi1_Click(object sender, RoutedEventArgs e)
{
PhoneCallTask call = new PhoneCallTask();
call.DisplayName = "Calling Taxi 1";
call.PhoneNumber = "1411111";
call.Show();
}
and i added:
using Microsoft.Phone.Tasks;
I think what I'm doing it wrong is that i use this function for several times the only thing that is changing is the name of taxi:
private void taxi2_Click (....)
and the call.DisplayName="Calling Taxi 2";
and call.PhoneNumber = "1422222";
Maybe I should use only one function like
private void PhoneCall_Click(object sender, RoutedEventArgs e)
{
string number="";
HttpUtility.UrlEncode((sender as Button).Tag.ToString());
if (NavigationContext.QueryString.TryGetValue("number", out number))
{
if (!string.IsNullOrWhiteSpace(number))
{
PhoneCallTask call = new PhoneCallTask();
call.DisplayName = "Taxi";
call.PhoneNumber = number;
call.Show();
}
}
}
and <Button ....... Tag="141111" .. />
just one thought, do you have permission added in manifest for this to work ? if so, writing what error is actually being thrown would be helpful in order to help you
ID_CAP_PHONEDIALER should be added
Related
I've got two questions about some problems on this code:
1) How can I stop the sounds? Sounds are in a separate thread, and I don't know how to stop them.
2) If I continue pressing the key this code will play a lot of times the same sounds and this is not realistic (imagine a piano keyboard: if I press a key and I continue pressing it just one sounds (the firs) will play). How to solve this problem?
I found a solution but now with threads I don't know how to do.
private void Form1_KeyDown(object sender, KeyPressEventArgs e)
{
[...] // Other code
th = new Thread(press));
th.Start(new object[] { key, name });
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
[...] // Other code
th = new Thread(leave);
th.Start(new object[] { key, name });
}
private void press(object data)
{
[...] // Other code
playSound(name);
}
private void leave(object data)
{
[...] // Other code
stopSound(name);
}
private void playSound(string name)
{
[...] // Other code
string url = Application.StartupPath + "\\notes\\" + name + ".wav";
var sound = new System.Windows.Media.MediaPlayer();
sound.Open(new Uri(url));
sound.play();
}
private void stopSound(string name)
{
???
}
Thank'you so much!
Create the thread as a variable in the class so that it can be accessed whenever you want.
Use the Handled Property to prevent the event from being handled again
e.Handled = true;
In my Silverlight application, I put the WCF call in my ViewModel class.
DateTime CurrentDateTime;
internal void GetDateTime()
{
var client = new WcfClient();
client.GetCurrentDateTimeCompleted += GetCurrentDateTimeCompleted;
client.GetCurrentDateTimeAsync();
}
private void GetCurrentDateTimeCompleted(object sender, GetCurrentDateTimeCompletedEventArgs args)
{
try
{
CurrentDateTime = args.Result;
}
Then in my code behind code some.xaml.cs file. I have a checkbox clicked event.
private void CheckBox_Clicked(object sender, RoutedEventArgs e)
{
var msgBoxControl = new MessageBoxControl();
msgBoxControl.Closed -= MessageBoxYesNo_Closed;
msgBoxControl.Closed += MessageBoxYesNo_Closed;
Inside the method MessageBoxYesNo_Closed, I call the method in the ViewModel class.
private void MessageBoxYesNo_Closed(object sender, EventArgs e)
{
try
{
this.ViewModel.GetDateTime();
curDateTime = this.ViewModel.CurrentDateTime;
My question is that sometimes the line curDateTime = this.ViewModel.CurrentDateTime; is executed before wcf call completed method, so I can't get the right value.
I guess that it may be there are two threads, one is in UI, the other one is in service call? Please don't use async/await as I have to use Visual Studio 2010.
Thanks
Get the solution, just add a while loop:
this.ViewModel.GetDateTime();
while (true)
{
this.ViewModel.CurrentDateTime = DateTime.Now;
if (this.ViewModel.CurrentDateTime != DateTime.MinValue)
break;
}
curDateTime = this.ViewModel.CurrentDateTime;
Im currently trying to fill a List in my UWP Project with data from a Webservice.
I have testet this code:
public void test()
{
BasicHttpBinding basicAuthBinding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
basicAuthBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress basicAuthEndpoint = new EndpointAddress("myURI");
LiveOdi.getODI_v1_PortTypeClient ptc = new LiveOdi.getODI_v1_PortTypeClient(basicAuthBinding, basicAuthEndpoint);
ptc.ClientCredentials.UserName.UserName = "myUsername";
ptc.ClientCredentials.UserName.Password = "myPasswort";
ptc.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 1);
string = ptc.getODIAsync("1").ToString();
}
private void button_Click(object sender, RoutedEventArgs e)
{
test();
textBlock.Text = string;
}
When I click the button to receive the data and display it , my Textblock only displays :
System.Threading.Tasks.TaskĀ“1[Test.LiveOdi.getODIResponse]
The same code works fine in forms with datagrid.datasource set to ptc.GetODI("1").
Edit :
Due to a bug (https://social.msdn.microsoft.com/Forums/sqlserver/en-US/84024ccf-7ef2-493e-a7bb-c354f42a354d/does-uwp-10-support-soap-services?forum=wpdevelop) I cannot use this approach anymore.
Can someone name an alternativ ?
ptc.getODIAsync("1") is async, and is returning a Task. That's why it's being displayed in the TextBox (as your code calls ToString on the Task).
You'll likely need to follow the async/await pattern so that you can get the response.
public async Task<string> test()
{
// put all of the web service setup code here, then:
string result = await ptc.getODIAsync("1");
return result;
}
// add async here so that the Click event can use Tasks with await/async
private async void button_Click(object sender, RoutedEventArgs e)
{
// stuff the value when the response returns from test
textBlock.Text = await test();
}
I have the piece of code as follows.
webBrowser.IsScriptEnabled = true;
webBrowser.InvokeScript("eval", "alert('hey')");
It gives An unknown error has occurred. Error: 80020006. Could you guide how to rectify this error.
There is no built-in browser window.alert in Windows Phone, but you can bind one as follows to call WebBrowser.ScriptNotify
//inside the page
window.alert = function (__msg) { window.external.notify(' + __msg + '); };
// in your C# code
this.webBrowser.ScriptNotify += new EventHandler<NotifyEventArgs>(Browser_ScriptNotify);
void Browser_ScriptNotify(object sender, NotifyEventArgs e)
{
MessageBox.Show(e.Value);
}
//later
this.CordovaView.Browser.IsScriptEnabled = true;
this.CordovaView.Browser.InvokeScript("alert", "ok");
On Cordova, there is also a Notification Plugin that you can plug by
window.alert = navigator.notification.alert;
Just be sure to enable Notification Plugin in config.xml
<feature name="Notification">
<param name="wp-package" value="Notification"/>
</feature>
It is caused by race condition. What we need to do is
this.CordovaView.Browser.LoadCompleted += Browser_LoadCompleted;
then
void Browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
this.CordovaView.Browser.IsScriptEnabled = true;
this.CordovaView.CordovaBrowser.IsScriptEnabled = true;
this.CordovaView.Browser.InvokeScript("setPushToken", push_uri);
}
I'm trying to create a custom download app. Its all working except for the download all button that cant pick up the "percent1" variable from the "DownloadProgressChangedEventArgs". I have instantiated it prior to the mainForm constructor but it wont read the changed value.
Here's the code, partially stripped since most of it isnt relevant to the question:
public partial class Main : Form
{
//Variables (not all, just the one im having issues with)
private double percentage1;
//Main form constructor
public Main(){...}
//Download File Async custom method
public void DldFile(string url, string fileName, string localPath, AsyncCompletedEventHandler completedName, DownloadProgressChangedEventHandler progressName)
{
WebClient webClient = new WebClient();
webClient.DownloadFileAsync(new Uri(url), localPath + "\\" + fileName);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(completedName);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(progressName);
}
//Button 1 click event to start download
private void btnDld1_Click(object sender, EventArgs e)
{
if (url1 != "" && Directory.Exists(localPath1))
{
_startDate1 = DateTime.Now;
DldFile(url1, fileName1, localPath1, completed1, progress1);
}
//took out the try/catch, other ifs to try and cut it down
}
//Download Progress Changed event for Download 1
public void progress1(object sender, DownloadProgressChangedEventArgs e)
{
percentage1 = e.ProgressPercentage; //THIS IS WHERE I WAS EXPECTING TO UPDATE "percentage1"
progressBar1.Value = int.Parse(Math.Truncate(percentage1).ToString());
}
//Button that starts all downloads click event where all my problems are at the moment
private void btnDldAll_Click(object sender, EventArgs e)
{
//The progress bar that should let me know the global status for all webClients
progressBarAll.Value = (
int.Parse(Math.Truncate(percentage1).ToString()) + //HERE IS MY PROBLEM
int.Parse(Math.Truncate(percentage2).ToString()) + //HERE IS MY PROBLEM
int.Parse(Math.Truncate(percentage3).ToString()) + //HERE IS MY PROBLEM
int.Parse(Math.Truncate(percentage4).ToString()) + //HERE IS MY PROBLEM
int.Parse(Math.Truncate(percentage5).ToString())) / 5; //HERE IS MY PROBLEM
//Checks if the link exists and starts it from the download button click event
if (url1 != "")
{
btnDld1.PerformClick();
}
//Continues for url2, 3, 4, 5 and else
}
}
So this is the shortest way i found of letting you know what im trying to pull off, if there's something missing please let me know, i'll try to add any info as fast as possible.
I have tried to instantiate "progress1" to try and acess its percentage1 variable, but it didnt work. I've tried doing the same thing with the webClient but didnt work either. I have used google and stackflow search to no avail. So im not sure if the question is too dumb, or there's a diferent way to look at the issue thats completely out of my mindset.
So main problem is updating the "percentage1" variable and using it.
There are other problems regarding the "progressBarAll.Value" calculation that will be solved when i can get my hands on the right value. So no need to worry about that if you see it.
Try not to think about 'using the event arguments outside the event'. Think about updating the state of your form.
Use properties to simplify the update logic:
public partial class Main : Form
{
private double percentage1;
private double percentage2;
private double percentage3;
private double percentage4;
private double percentage5;
private double Percentage1
{
get
{
return this.percentage1;
}
set
{
this.percentage1 = value;
this.UpdatePercentageAll(); // this will update overall progress whenever the first one changes
progressBar1.Value = GetValueFromPercentage(value);
}
}
private double Percentage2
// same code as for Percentage1
void UpdatePercentageAll()
{
this.PercentageAll = (this.Percentage1 + this.Percentage2 + this.Percentage3 + this.Percentage4 + this.Percentage5) / 5;
}
static int GetValueFromPercentage(double percentage)
{
return (int)Math.Truncate(percentage);
}
double percentageAll;
private double PercentageAll
{
get
{
return this.percentageAll;
}
set
{
this.percentageAll = value;
progressBarAll.Value = GetValueFromPercentage(value);
}
}
//Download File Async custom method
public void DldFile(string url, string fileName, string localPath, AsyncCompletedEventHandler completedName, DownloadProgressChangedEventHandler progressName)
{
WebClient webClient = new WebClient();
webClient.DownloadFileAsync(new Uri(url), localPath + "\\" + fileName);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(completedName);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(progressName);
}
//Button 1 click event to start download
private void btnDld1_Click(object sender, EventArgs e)
{
if (url1 != "" && Directory.Exists(localPath1))
{
this.StartDownloadFile1();
}
//took out the try/catch, other ifs to try and cut it down
}
void StartDownloadFile1()
{
this.Percentage1 = 0;
_startDate1 = DateTime.Now;
DldFile(url1, fileName1, localPath1, completed1, progress1);
}
//Download Progress Changed event for Download 1
public void progress1(object sender, DownloadProgressChangedEventArgs e)
{
this.Percentage1 = e.ProgressPercentage; // update property, not field
//this will be done in property setters
//progressBar1.Value = int.Parse(Math.Truncate(percentage1).ToString());
}
// then add similar code for other download buttons
//Button that starts all downloads click event where all my problems are at the moment
private void btnDldAll_Click(object sender, EventArgs e)
{
//Checks if the link exists and starts it from the download button click event
if (url1 != "")
{
this.StartDownloadFile1();
}
//Continues for url2, 3, 4, 5 and else
}
}
I would refactor the code even further, but I think it will be easier for you to understand if the code is closer to the original.
The main idea is to create a set of linked properties which work like mathematical functions. When writing the PercentageX properties I'm kind of saying 'let PercentageAll be the average of all percentages'. Then I have each download update it's own progress. Once any progress is updated it updates the average, and I don't have to rememver that inside the progress changed event handler.
And the last point is updating progress bars from percentage properties. It's quite straightforward: once a percentage is changed, I need to update a bar. If so, why bother writing something like
this.Percentage1 = x;
this.progressBar1.Value = (int)Math.Truncate(x);
In this case I have to remember everywhere that once I change the Percentage1 I have to update the bar. And in my example I just create a strict rule for that which is only in one place and works everytime. So I just cannot forget it. And if I need to change the rule, I need to change only one place, so again I cannot make a mistake.
The technique I demonstrate can be expressed as a well-known rule: 'one rule - one place', which means that you should try to have only single place in code that expresses each logical rule that exists in your program. It is a very important idea, I suggest you learn and use it.